src/stdlib/SDL_qsort.c
changeset 10599 ade40eb390dc
parent 10116 418691d83f6a
child 10737 3406a0f8b041
equal deleted inserted replaced
10598:85f444d7a73d 10599:ade40eb390dc
   273         else doLeft				\
   273         else doLeft				\
   274       }
   274       }
   275 
   275 
   276 /* and so is the pivoting logic (note: last is inclusive): */
   276 /* and so is the pivoting logic (note: last is inclusive): */
   277 #define Pivot(swapper,sz)			\
   277 #define Pivot(swapper,sz)			\
   278   if (last-first>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\
   278   if ((size_t)(last-first)>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\
   279   else {	\
   279   else {	\
   280     if (compare(first,mid)<0) {			\
   280     if (compare(first,mid)<0) {			\
   281       if (compare(mid,last)>0) {		\
   281       if (compare(mid,last)>0) {		\
   282         swapper(mid,last);			\
   282         swapper(mid,last);			\
   283         if (compare(first,mid)>0) swapper(first,mid);\
   283         if (compare(first,mid)>0) swapper(first,mid);\
   411   size_t trunc=TRUNC_nonaligned*size;
   411   size_t trunc=TRUNC_nonaligned*size;
   412   assert(pivot!=0);
   412   assert(pivot!=0);
   413 
   413 
   414   first=(char*)base; last=first+(nmemb-1)*size;
   414   first=(char*)base; last=first+(nmemb-1)*size;
   415 
   415 
   416   if (last-first>=trunc) {
   416   if ((size_t)(last-first)>=trunc) {
   417     char *ffirst=first, *llast=last;
   417     char *ffirst=first, *llast=last;
   418     while (1) {
   418     while (1) {
   419       /* Select pivot */
   419       /* Select pivot */
   420       { char * mid=first+size*((last-first)/size >> 1);
   420       { char * mid=first+size*((last-first)/size >> 1);
   421         Pivot(SWAP_nonaligned,size);
   421         Pivot(SWAP_nonaligned,size);
   442   size_t trunc=TRUNC_aligned*size;
   442   size_t trunc=TRUNC_aligned*size;
   443   assert(pivot!=0);
   443   assert(pivot!=0);
   444 
   444 
   445   first=(char*)base; last=first+(nmemb-1)*size;
   445   first=(char*)base; last=first+(nmemb-1)*size;
   446 
   446 
   447   if (last-first>=trunc) {
   447   if ((size_t)(last-first)>=trunc) {
   448     char *ffirst=first,*llast=last;
   448     char *ffirst=first,*llast=last;
   449     while (1) {
   449     while (1) {
   450       /* Select pivot */
   450       /* Select pivot */
   451       { char * mid=first+size*((last-first)/size >> 1);
   451       { char * mid=first+size*((last-first)/size >> 1);
   452         Pivot(SWAP_aligned,size);
   452         Pivot(SWAP_aligned,size);