[sldev] Compare functions (llspatialpartition.h)

Nicholaz Beresford nicholaz at blueflash.cc
Thu Jul 5 08:59:48 PDT 2007


There are two compare functions in llspatialpartition.h which I believe
are wrong.

When doing pointer compares, if NULL pointers are involved I think the
result should be consistent (i.e. a NULL either being always considered
more or less than a pointer value).  With these implementations however,
NULL is considered greater if it appears as lhs, but if it appears as
rhs the function returns also TRUE, which implicitely means that NULL
is lesser (as far as I understand it, these compare functions for std::sort
are bound to return if left is greater than right.  Also in case both are
NULL, I think false should be returned (neither is greater).

Shouldn't that be (assuming that NULL should be greater, to be sorted to
the end of the list):

return lhs != rhs && (lhs == NULL || (rhs != NULL && lhs->mTexture > rhs->mTexture));

Or am I missing something?



Original snippet:

struct CompareTexturePtr
{
     bool operator()(const LLDrawInfo* const& lhs, const LLDrawInfo* const& rhs)
     {

         return lhs == NULL || rhs == NULL || lhs->mTexture > rhs->mTexture;
     }
};

struct CompareBump
{
     bool operator()(const LLDrawInfo* const& lhs, const LLDrawInfo* const& rhs)
     {
         return lhs == NULL || rhs == NULL || lhs->mBump > rhs->mBump;
     }
};

-- 
Second Life from the inside out:
http://nicholaz-beresford.blogspot.com/


More information about the SLDev mailing list