Revert "optimization that does not work, but is maybe not totally bad"
This reverts commit cebc516125e67dd0928a97a577d18564b0db064c.
This commit is contained in:
parent
cebc516125
commit
12d30a588a
37
qsort.h
37
qsort.h
@ -102,14 +102,15 @@ static inline pret3 partition3(uint32_t array[], int low, int high, uint32_t piv
|
||||
|
||||
/* index until smaller or eq elements lay */
|
||||
int i = (low - 1);
|
||||
/* index until smaller or eq elements lay */
|
||||
int i2 = (high + 1);
|
||||
uint32_t pc = 0;
|
||||
|
||||
/* traverse each element of the array */
|
||||
/* compare them with the pivot */
|
||||
int j2 = high; // j2 > i; --j2) {
|
||||
#pragma GCC unroll 4
|
||||
for (int j = low; j <= high; ++j) {
|
||||
/* Branchless pivot-count */
|
||||
pc += (array[j] == pivot);
|
||||
|
||||
if(array[j] < pivot) {
|
||||
/* if element smaller than pivot is found */
|
||||
/* swap it with the greater element pointed by i */
|
||||
@ -118,16 +119,28 @@ static inline pret3 partition3(uint32_t array[], int low, int high, uint32_t piv
|
||||
/* swap element at i with element at j */
|
||||
swapit(&array[i], &array[j]);
|
||||
}
|
||||
if(j2 > i) {
|
||||
if (array[j2] > pivot) {
|
||||
/* if element smaller than pivot is found */
|
||||
/* swap it with the greater element pointed by i */
|
||||
--i2;
|
||||
}
|
||||
|
||||
/* swap element at i with element at j */
|
||||
swapit(&array[i2], &array[j2]);
|
||||
}
|
||||
--j2;
|
||||
/* Can spare out the second loop in these cases */
|
||||
if(pc < 2) {
|
||||
pret3 ret;
|
||||
ret.leftend = i;
|
||||
ret.rightend = i + 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* index until smaller or eq elements lay */
|
||||
int i2 = (high + 1);
|
||||
|
||||
#pragma GCC unroll 4
|
||||
for (int j = high; j > i; --j) {
|
||||
if (array[j] > pivot) {
|
||||
/* if element smaller than pivot is found */
|
||||
/* swap it with the greater element pointed by i */
|
||||
--i2;
|
||||
|
||||
/* swap element at i with element at j */
|
||||
swapit(&array[i2], &array[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user