pike.git/
src/
array.c
Branch:
Tag:
Non-build tags
All tags
No tags
2007-12-24
2007-12-24 15:33:43 by Henrik Grubbström (Grubba) <grubba@grubba.org>
3325cd5830250e64188cd89c33c1aa5bef77e9cb (
30
lines) (+
28
/-
2
)
[
Show
|
Annotate
]
Branch:
7.9
Optimized sorting of arrays containing only integers.
Rev: src/array.c:1.197
2:
|| This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: array.c,v 1.
196
2007/12/
17
18
:
00
:
55
grubba Exp $
+
|| $Id: array.c,v 1.
197
2007/12/
24
15
:
33
:
43
grubba Exp $
*/ #include "global.h"
1174:
#undef TYPE #undef ID
+
/* Same, but only integers. */
+
static int alpha_int_svalue_cmpfun(const struct svalue *a, const struct svalue *b)
+
{
+
#ifdef PIKE_DEBUG
+
if ((a->type != T_INT) || (b->type != T_INT)) {
+
Pike_fatal("Invalid elements in supposedly integer array.\n");
+
}
+
#endif /* PIKE_DEBUG */
+
if(a->u.integer < b->u.integer) return -1;
+
if(a->u.integer > b->u.integer) return 1;
+
return 0;
+
}
+
+
#define CMP(X,Y) alpha_int_svalue_cmpfun(X,Y)
+
#define TYPE struct svalue
+
#define ID low_sort_int_svalues
+
#include "fsort_template.h"
+
#undef CMP
+
#undef TYPE
+
#undef ID
+
/** This sort is unstable. */ PMOD_EXPORT void sort_array_destructively(struct array *v) { if(!v->size) return;
-
+
if (v->type_field == BIT_INT) {
+
low_sort_int_svalues(ITEM(v), ITEM(v)+v->size-1);
+
} else {
low_sort_svalues(ITEM(v), ITEM(v)+v->size-1); }
-
+
}
#define SORT_BY_INDEX #define EXTRA_LOCALS int cmpfun_res;