[sldev] Compare functions (llspatialpartition.h)

Soft Linden soft at lindenlab.com
Tue Jul 10 08:57:26 PDT 2007


I'm adding this to my list of things to look at. It's probably
harmless, but I should at least do a blame and ask if it was
intentional.

On 7/5/07, Nicholaz Beresford <nicholaz at blueflash.cc> wrote:
>
> 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/
> _______________________________________________
> Click here to unsubscribe or manage your list subscription:
> /index.html
>


More information about the SLDev mailing list