pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:1:   /*   || 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"   #include "svalue.h"   #include "array.h"   #include "object.h"   #include "las.h"   #include "stralloc.h"   #include "interpret.h"   #include "opcodes.h"
pike.git/src/array.c:1167:   }      #define CMP(X,Y) alpha_svalue_cmpfun(X,Y)   #define TYPE struct svalue   #define ID low_sort_svalues   #include "fsort_template.h"   #undef CMP   #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;   #define CMP(X,Y) ((cmpfun_res = alpha_svalue_cmpfun(svals + X, svals + Y)) ? \    cmpfun_res : pos[X] - pos[Y])   #define SWAP(X,Y) { \    {struct svalue tmp = svals[X]; svals[X] = svals[Y]; svals[Y] = tmp;} \    {int tmp = pos[X]; pos[X] = pos[Y]; pos[Y] = tmp;} \   }   #define TYPE struct svalue