Don't touch code that we brought in from other sources
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401341
This commit is contained in:
parent
5d53175e4d
commit
098fe1b8e9
1 changed files with 20 additions and 13 deletions
|
@ -47,10 +47,17 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
*/
|
*/
|
||||||
#define assert(X)
|
|
||||||
#include "SDL_stdlib.h"
|
#include "SDL_stdlib.h"
|
||||||
#include "SDL_string.h"
|
#include "SDL_string.h"
|
||||||
|
|
||||||
|
#define assert(X)
|
||||||
|
#define malloc SDL_malloc
|
||||||
|
#define free SDL_free
|
||||||
|
#define memcpy SDL_memcpy
|
||||||
|
#define memmove SDL_memmove
|
||||||
|
#define qsort SDL_qsort
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_QSORT
|
#ifndef HAVE_QSORT
|
||||||
|
|
||||||
static char _ID[]="<qsort.c gjm 1.12 1998-03-19>";
|
static char _ID[]="<qsort.c gjm 1.12 1998-03-19>";
|
||||||
|
@ -233,9 +240,9 @@ typedef struct { char * first; char * last; } stack_entry;
|
||||||
/* Shift everything in [test,first) \
|
/* Shift everything in [test,first) \
|
||||||
* up by one, and place |first| \
|
* up by one, and place |first| \
|
||||||
* where |test| is. */ \
|
* where |test| is. */ \
|
||||||
SDL_memcpy(pivot,first,size); \
|
memcpy(pivot,first,size); \
|
||||||
SDL_memmove(test+size,test,first-test); \
|
memmove(test+size,test,first-test); \
|
||||||
SDL_memcpy(test,pivot,size); \
|
memcpy(test,pivot,size); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +305,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
|
||||||
stack_entry stack[STACK_SIZE];
|
stack_entry stack[STACK_SIZE];
|
||||||
int stacktop=0;
|
int stacktop=0;
|
||||||
char *first,*last;
|
char *first,*last;
|
||||||
char *pivot=SDL_malloc(size);
|
char *pivot=malloc(size);
|
||||||
size_t trunc=TRUNC_nonaligned*size;
|
size_t trunc=TRUNC_nonaligned*size;
|
||||||
assert(pivot!=0);
|
assert(pivot!=0);
|
||||||
|
|
||||||
|
@ -310,7 +317,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
|
||||||
/* Select pivot */
|
/* Select pivot */
|
||||||
{ char * mid=first+size*((last-first)/size >> 1);
|
{ char * mid=first+size*((last-first)/size >> 1);
|
||||||
Pivot(SWAP_nonaligned,size);
|
Pivot(SWAP_nonaligned,size);
|
||||||
SDL_memcpy(pivot,mid,size);
|
memcpy(pivot,mid,size);
|
||||||
}
|
}
|
||||||
/* Partition. */
|
/* Partition. */
|
||||||
Partition(SWAP_nonaligned,size);
|
Partition(SWAP_nonaligned,size);
|
||||||
|
@ -320,7 +327,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
|
||||||
}
|
}
|
||||||
PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size);
|
PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size);
|
||||||
Insertion(SWAP_nonaligned);
|
Insertion(SWAP_nonaligned);
|
||||||
SDL_free(pivot);
|
free(pivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qsort_aligned(void *base, size_t nmemb, size_t size,
|
static void qsort_aligned(void *base, size_t nmemb, size_t size,
|
||||||
|
@ -329,7 +336,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size,
|
||||||
stack_entry stack[STACK_SIZE];
|
stack_entry stack[STACK_SIZE];
|
||||||
int stacktop=0;
|
int stacktop=0;
|
||||||
char *first,*last;
|
char *first,*last;
|
||||||
char *pivot=SDL_malloc(size);
|
char *pivot=malloc(size);
|
||||||
size_t trunc=TRUNC_aligned*size;
|
size_t trunc=TRUNC_aligned*size;
|
||||||
assert(pivot!=0);
|
assert(pivot!=0);
|
||||||
|
|
||||||
|
@ -341,7 +348,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size,
|
||||||
/* Select pivot */
|
/* Select pivot */
|
||||||
{ char * mid=first+size*((last-first)/size >> 1);
|
{ char * mid=first+size*((last-first)/size >> 1);
|
||||||
Pivot(SWAP_aligned,size);
|
Pivot(SWAP_aligned,size);
|
||||||
SDL_memcpy(pivot,mid,size);
|
memcpy(pivot,mid,size);
|
||||||
}
|
}
|
||||||
/* Partition. */
|
/* Partition. */
|
||||||
Partition(SWAP_aligned,size);
|
Partition(SWAP_aligned,size);
|
||||||
|
@ -351,7 +358,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size,
|
||||||
}
|
}
|
||||||
PreInsertion(SWAP_aligned,TRUNC_aligned,size);
|
PreInsertion(SWAP_aligned,TRUNC_aligned,size);
|
||||||
Insertion(SWAP_aligned);
|
Insertion(SWAP_aligned);
|
||||||
SDL_free(pivot);
|
free(pivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qsort_words(void *base, size_t nmemb,
|
static void qsort_words(void *base, size_t nmemb,
|
||||||
|
@ -360,7 +367,7 @@ static void qsort_words(void *base, size_t nmemb,
|
||||||
stack_entry stack[STACK_SIZE];
|
stack_entry stack[STACK_SIZE];
|
||||||
int stacktop=0;
|
int stacktop=0;
|
||||||
char *first,*last;
|
char *first,*last;
|
||||||
char *pivot=SDL_malloc(WORD_BYTES);
|
char *pivot=malloc(WORD_BYTES);
|
||||||
assert(pivot!=0);
|
assert(pivot!=0);
|
||||||
|
|
||||||
first=(char*)base; last=first+(nmemb-1)*WORD_BYTES;
|
first=(char*)base; last=first+(nmemb-1)*WORD_BYTES;
|
||||||
|
@ -398,12 +405,12 @@ fprintf(stderr,"pivot=%d\n",*(int*)pivot);
|
||||||
*pr=*pl; }
|
*pr=*pl; }
|
||||||
if (pr!=(int*)first) *pr=*(int*)pivot;
|
if (pr!=(int*)first) *pr=*(int*)pivot;
|
||||||
}
|
}
|
||||||
SDL_free(pivot);
|
free(pivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void SDL_qsort(void *base, size_t nmemb, size_t size,
|
void qsort(void *base, size_t nmemb, size_t size,
|
||||||
int (*compare)(const void *, const void *)) {
|
int (*compare)(const void *, const void *)) {
|
||||||
|
|
||||||
if (nmemb<=1) return;
|
if (nmemb<=1) return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue