fast path for sorted_array_insert
parent
0c437d3799
commit
f6c5256264
|
|
@ -59,9 +59,15 @@ static char *sorted_array_bsearch(SortedArrayContext *ctx, char *base,
|
||||||
int sorted_array_insert(SortedArrayContext *ctx,
|
int sorted_array_insert(SortedArrayContext *ctx,
|
||||||
void *base, int *count, const void *elt)
|
void *base, int *count, const void *elt)
|
||||||
{
|
{
|
||||||
|
char *current;
|
||||||
|
|
||||||
|
if (*count == 0 || ctx->compare_func((char *)base +
|
||||||
|
ctx->element_size * (*count - 1), elt) < 0)
|
||||||
|
{ //fast path
|
||||||
|
current = (char *)base + ctx->element_size * (*count);
|
||||||
|
} else {
|
||||||
int insert_pos;
|
int insert_pos;
|
||||||
int move_count;
|
int move_count;
|
||||||
char *current;
|
|
||||||
char *found;
|
char *found;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
|
|
@ -85,6 +91,7 @@ int sorted_array_insert(SortedArrayContext *ctx,
|
||||||
memmove((char *)base + ctx->element_size * (insert_pos + 1),
|
memmove((char *)base + ctx->element_size * (insert_pos + 1),
|
||||||
current, ctx->element_size * move_count);
|
current, ctx->element_size * move_count);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (ctx->element_size) {
|
switch (ctx->element_size) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue