mirror of
https://github.com/cc65/cc65.git
synced 2025-01-25 11:30:06 +00:00
Size optimizations.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5714 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
c66185259b
commit
383157e743
@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void QuickSort (void* Base, int Lo, int Hi, size_t Size,
|
static void QuickSort (register unsigned char* Base, int Lo, int Hi,
|
||||||
|
register size_t Size,
|
||||||
int (*Compare)(const void*, const void*))
|
int (*Compare)(const void*, const void*))
|
||||||
/* Internal recursive function. Works with ints, but this shouldn't be
|
/* Internal recursive function. Works with ints, but this shouldn't be
|
||||||
* a problem.
|
* a problem.
|
||||||
@ -18,28 +19,25 @@ static void QuickSort (void* Base, int Lo, int Hi, size_t Size,
|
|||||||
{
|
{
|
||||||
int I, J;
|
int I, J;
|
||||||
|
|
||||||
/* Get a char pointer */
|
|
||||||
unsigned char* B = Base;
|
|
||||||
|
|
||||||
/* Quicksort */
|
/* Quicksort */
|
||||||
while (Hi > Lo) {
|
while (Hi > Lo) {
|
||||||
I = Lo + Size;
|
I = Lo + Size;
|
||||||
J = Hi;
|
J = Hi;
|
||||||
while (I <= J) {
|
while (I <= J) {
|
||||||
while (I <= J && Compare (B + Lo, B + I) >= 0) {
|
while (I <= J && Compare (Base + Lo, Base + I) >= 0) {
|
||||||
I += Size;
|
I += Size;
|
||||||
}
|
}
|
||||||
while (I <= J && Compare (B + Lo, B + J) < 0) {
|
while (I <= J && Compare (Base + Lo, Base + J) < 0) {
|
||||||
J -= Size;
|
J -= Size;
|
||||||
}
|
}
|
||||||
if (I <= J) {
|
if (I <= J) {
|
||||||
_swap (B + I, B + J, Size);
|
_swap (Base + I, Base + J, Size);
|
||||||
I += Size;
|
I += Size;
|
||||||
J -= Size;
|
J -= Size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (J != Lo) {
|
if (J != Lo) {
|
||||||
_swap (B + J, B + Lo, Size);
|
_swap (Base + J, Base + Lo, Size);
|
||||||
}
|
}
|
||||||
if (((unsigned) J) * 2 > (Hi + Lo)) {
|
if (((unsigned) J) * 2 > (Hi + Lo)) {
|
||||||
QuickSort (Base, J + Size, Hi, Size, Compare);
|
QuickSort (Base, J + Size, Hi, Size, Compare);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user