Branch: Tag:

2014-05-10

2014-05-10 11:48:40 by Per Hedbor <ph@opera.com>

binary_findstring_pcharp introduced.

It actually checks if the string should be narrowed.
Used by cpp to avoid code duplication for different shifts.

Removed binary_findstring_shift

526:    return internal_findstring(foo, l, 0, StrHash(foo,l));   }    - struct pike_string *binary_findstring_shift(const void *foo, enum size_shift shift, ptrdiff_t l) + struct pike_string *binary_findstring_pcharp(PCHARP foo, ptrdiff_t l)   { -  return internal_findstring(foo, l, shift, low_do_hash(foo,l,shift)); +  int in = foo.shift; +  void *tmp = NULL; +  struct pike_string *res; +  +  if( foo.shift == 2 ) +  foo.shift=find_magnitude2( (void*)foo.ptr, l ); +  else if( foo.shift == 1 ) +  foo.shift=find_magnitude1( (void*)foo.ptr, l ); +  +  if( foo.shift != in ) +  { +  tmp = malloc( l * (1<<foo.shift) ); +  switch(in) +  { +  case 1: +  convert_1_to_0( tmp, (void*)foo.ptr, l ); +  break; +  case 2: +  if( foo.shift == 1 ) +  convert_2_to_1( tmp, (void*)foo.ptr, l ); +  else +  convert_2_to_0( tmp, (void*)foo.ptr, l );    } -  +  foo.ptr = tmp; +  }    -  +  res=internal_findstring(foo.ptr, l, foo.shift, +  low_do_hash(foo.ptr,l,foo.shift)); +  +  if( tmp ) +  free( tmp ); +  return res; + } +    struct pike_string *findstring(const char *foo)   {    return binary_findstring(foo, strlen(foo));