Feature Request - Remove stdlib sort

Hi,

This is just a suggested modification to the b2BroadPhase definition to help make box2d easier to port for Android.

At present, the Android NDK does not provide a complete stdlib implementation and whilst in most cases this does not create a problem, the is one use of the "std::sort" function in box2d which is not available on Android.

Rather than trying to port an entire stdlib implementation to Android, I have made the following changes:

in b2BroadPhase.h

Current:
Code:
   // Sort the pair buffer to expose duplicates.
   std::sort(m_pairBuffer, m_pairBuffer + m_pairCount, b2PairLessThan);


Changed to:
Code:
   qsort(m_pairBuffer, sizeof(m_pairBuffer) / sizeof(struct b2Pair) , sizeof(struct b2Pair), b2PairCompareQSort);


Which calls a new function:
Code:
//The return value of this function should represent whether elem1 is considered less than,
//equal to, or greater than elem2 by returning, respectively, a negative value, zero or a positive value.
inline int b2PairCompareQSort(const void * elem1, const void * elem2)
{
   b2Pair* pair1 = (b2Pair*) elem1;
   b2Pair* pair2 = (b2Pair*) elem2;

   if (pair1->proxyIdA < pair2->proxyIdA)
   {
      return -1;
   }

   if (pair1->proxyIdA == pair2->proxyIdA)
   {
      if( pair1->proxyIdB < pair2->proxyIdB ) {
         return -1;
      }
      else if(pair1->proxyIdB > pair2->proxyIdB) {
         return 1;
      }
      else {
         return 0;
      }
   }
   else {
      return 1;
   }
}


It's not a big deal for me to make this change for Android, it would just make getting updates from SVN a little easier as it would remove the need to manually deal with merge conflicts.

Of course I think std::sort is a bit faster than qsort, so it may be that us Android people need to just suck it up and deal with it.

Just a suggestion.

Cheers,

Jason.
May not be required thanks to JeroMiya in post

viewtopic.php?f=7&t=4756&start=0

Original thread: https://box2d.org/forum/viewtopic.php?t=4817