pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:639:    {    MEMMOVE((char *)(ITEM(v)+index),    (char *)(ITEM(v)+index+1),    (v->size-index-1)*sizeof(struct svalue));    }    v->size--;    return v;    }   }    + static ptrdiff_t fast_array_search( struct array *v, struct svalue *s, ptrdiff_t start ) + { +  ptrdiff_t e; +  /* Why search for something that is not there? +  * however, we must explicitly check for searches +  * for destructed objects/functions +  */ +  if((v->type_field & (1 << TYPEOF(*s))) || +  (UNSAFE_IS_ZERO(s) && (v->type_field & (BIT_FUNCTION|BIT_OBJECT))) || +  ( (v->type_field | (1<<TYPEOF(*s))) & BIT_OBJECT )) /* for overloading */ +  { +  struct svalue *ip = ITEM(v); +  for(e=start;e<v->size;e++) +  if(is_eq(ip+e,s)) +  return e; +  } +  return -1; + } +    /**    * Search for in svalue in an array.    * @param v the array to search    * @param s the value to search for    * @param start the index to start search at    * @return the index if found, -1 otherwise    */   PMOD_EXPORT ptrdiff_t array_search(struct array *v, struct svalue *s,    ptrdiff_t start)   { -  ptrdiff_t e; -  +    #ifdef PIKE_DEBUG    if(start<0)    Pike_fatal("Start of find_index is less than zero.\n");   #endif -  -  check_destructed(s); -  +    #ifdef PIKE_DEBUG    if(d_flag > 1) array_check_type_field(v);   #endif -  /* Why search for something that is not there? -  * however, we must explicitly check for searches -  * for destructed objects/functions -  */ -  if((v->type_field & (1 << TYPEOF(*s))) || -  (UNSAFE_IS_ZERO(s) && (v->type_field & (BIT_FUNCTION|BIT_OBJECT))) || -  ( (v->type_field | (1<<TYPEOF(*s))) & BIT_OBJECT )) /* for overloading */ -  { -  if(start) -  { -  for(e=start;e<v->size;e++) -  if(is_eq(ITEM(v)+e,s)) return e; -  }else{ -  TYPE_FIELD t=0; -  for(e=0;e<v->size;e++) -  { -  if(is_eq(ITEM(v)+e,s)) return e; -  t |= 1<<TYPEOF(ITEM(v)[e]); +  check_destructed(s); +  return fast_array_search( v, s, start );   } -  v->type_field=t; -  } -  } -  return -1; - } +       /**    * Slice a piece of an array (conditionally destructively)    * @param v the array to slice    * @param start the beginning element to be included    * @param end the element beyond the end of the slice    * @return an array consisting of v[start..end-1]    */   PMOD_EXPORT struct array *slice_array(struct array *v, ptrdiff_t start,    ptrdiff_t end)
pike.git/src/array.c:2619:      /** 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,    struct svalue *to)   {    ptrdiff_t i = -1; -  -  while((i=array_search(a,from,i+1)) >= 0) array_set_index(a,i,to); +  check_array_for_destruct(a); +  while((i=fast_array_search(a,from,i+1)) >= 0) array_set_index(a,i,to);   }      #ifdef PIKE_DEBUG   PMOD_EXPORT void check_array(struct array *a)   {    INT32 e;       if(a->next && a->next->prev != a)    Pike_fatal("array->next->prev != array.\n");