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.207 2008/05/11 14:55:52 mast Exp $ + || $Id: array.c,v 1.208 2008/05/12 13:24:44 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:377:    {    struct svalue tmp;    tmp.type=T_ARRAY;    tmp.u.array=a;    index_error(0,0,0,&tmp,ind,"Array index is neither int nor string.\n");    }    }   }      /** -  * Insert an svalue into an array and grow the array if nessesary. +  * Insert an svalue into an array and grow the array if necessary.    */   PMOD_EXPORT struct array *array_insert(struct array *v,struct svalue *s,INT32 index)   {   #ifdef PIKE_DEBUG    if(index<0 || index>v->size)    Pike_fatal("Illegal index in low level insert routine.\n");   #endif       /* Can we fit it into the existing block? */    if(v->refs<=1 && (v->malloced_size > v->size))
pike.git/src/array.c:411:    assert_free_svalue (ITEM(v) + index);    v->size++;    }else{    struct array *ret;       ret = array_set_flags(allocate_array_no_init(v->size+1, v->size + 1),    v->flags);    ret->type_field = v->type_field;       MEMCPY(ITEM(ret), ITEM(v), sizeof(struct svalue) * index); -  MEMCPY(ITEM(ret)+index+1, ITEM(v)+index, sizeof(struct svalue) * (v->size-index)); +  MEMCPY(ITEM(ret)+index+1, ITEM(v)+index, +  sizeof(struct svalue) * (v->size-index));    assert_free_svalue (ITEM(ret) + index); -  v->size=0; +  if (v->refs == 1) { +  /* Optimization: Steal the references. */ +  v->size = 0; +  } else if (v->type_field & BIT_REF_TYPES) { +  /* Adjust the references. */ +  int e = v->size; +  struct svalue *s = ITEM(ret); +  while (e--) { +  if (s->type <= MAX_REF_TYPE) add_ref(s->u.dummy); +  s++; +  } +  }    free_array(v);    v=ret;    }       array_set_index_no_free (v,index,s);       return v;   }      /*