src/stdlib/SDL_qsort.c
changeset 1456 84de7511f79f
parent 1402 d910939febfa
child 1662 782fd950bd46
child 1895 c121d94672cb
child 4186 5bacec0933f5
equal deleted inserted replaced
1455:f487bb150acc 1456:84de7511f79f
   261 
   261 
   262 /* ---------------------------------------------------------------------- */
   262 /* ---------------------------------------------------------------------- */
   263 
   263 
   264 static char * pivot_big(char *first, char *mid, char *last, size_t size,
   264 static char * pivot_big(char *first, char *mid, char *last, size_t size,
   265                         int compare(const void *, const void *)) {
   265                         int compare(const void *, const void *)) {
   266   int d=(((last-first)/size)>>3)*size;
   266   size_t d=(((last-first)/size)>>3)*size;
   267   char *m1,*m2,*m3;
   267   char *m1,*m2,*m3;
   268   { char *a=first, *b=first+d, *c=first+2*d;
   268   { char *a=first, *b=first+d, *c=first+2*d;
   269 #ifdef DEBUG_QSORT
   269 #ifdef DEBUG_QSORT
   270 fprintf(stderr,"< %d %d %d\n",*(int*)a,*(int*)b,*(int*)c);
   270 fprintf(stderr,"< %d %d %d\n",*(int*)a,*(int*)b,*(int*)c);
   271 #endif
   271 #endif
   412 
   412 
   413 void qsort(void *base, size_t nmemb, size_t size,
   413 void qsort(void *base, size_t nmemb, size_t size,
   414            int (*compare)(const void *, const void *)) {
   414            int (*compare)(const void *, const void *)) {
   415 
   415 
   416   if (nmemb<=1) return;
   416   if (nmemb<=1) return;
   417   if (((int)base|size)&(WORD_BYTES-1))
   417   if (((uintptr_t)base|size)&(WORD_BYTES-1))
   418     qsort_nonaligned(base,nmemb,size,compare);
   418     qsort_nonaligned(base,nmemb,size,compare);
   419   else if (size!=WORD_BYTES)
   419   else if (size!=WORD_BYTES)
   420     qsort_aligned(base,nmemb,size,compare);
   420     qsort_aligned(base,nmemb,size,compare);
   421   else
   421   else
   422     qsort_words(base,nmemb,compare);
   422     qsort_words(base,nmemb,compare);