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.198 2008/01/26 22:34:17 mast Exp $ + || $Id: array.c,v 1.199 2008/01/29 20:10:06 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:2469:    ref_push_array(cycl);    }       END_CYCLIC();   }      /** Reverse the elements in an array. If the array has more than one    * reference, the array will be reversed into a new array. Otherwise    * the array will be destructively reversed in place.    */ - PMOD_EXPORT struct array *reverse_array(struct array *a) + PMOD_EXPORT struct array *reverse_array(struct array *a, int start, int end)   {    INT32 e;    struct array *ret;    -  +  if ((end <= start) || (start >= a->size)) { +  add_ref(a); +  return a; +  } +  if (end >= a->size) { +  end = a->size; +  } else { +  end++; +  } +     if(a->refs == 1)    /* Reverse in-place. */    {    struct svalue *tmp0, *tmp1, swap;    -  tmp0 = ITEM(a); -  tmp1 = ITEM(a) + a->size; -  for(e = a->size>>1; 0 < e; e--) -  { +  tmp0 = ITEM(a) + start; +  tmp1 = ITEM(a) + end; +  while (tmp0 < tmp1) {    swap = *tmp0;    *(tmp0++) = *(--tmp1);    *tmp1 = swap;    }       /* FIXME: What about the flags field? */       add_ref(a);    return a;    }    -  +  // fprintf(stderr, "R"); +     ret=allocate_array_no_init(a->size,0); -  for(e=0;e<a->size;e++) -  assign_svalue_no_free(ITEM(ret)+e,ITEM(a)+a->size+~e); +  for(e=0;e<start;e++) +  assign_svalue_no_free(ITEM(ret)+e,ITEM(a)+e); +  for(;e<end;e++) +  assign_svalue_no_free(ITEM(ret)+e,ITEM(a)+end+~e-start); +  for(;e<a->size;e++) +  assign_svalue_no_free(ITEM(ret)+e,ITEM(a)+e);    ret->type_field = a->type_field;    return ret;   }      /** Replaces all from elements in array a with to elements. Called    * from replaces when first argument is an array. The replace is applied    * desctructivly.    */   void array_replace(struct array *a,    struct svalue *from,