Branch: Tag:


2013-05-31 17:03:44 by Per Hedbor <>

Added min- and max- range-indicators to strings.

Also added flags indicating if a string is lowercase or uppercase.

The min/max is only calculated on demand to avoid any slowdowns.

This makes upper_case/lower_case(X), where X is an already lowercased
string very fast ('search' also utilize the ranges when available, so
search(string,"\0") is very fast if there are no null characters in
the string).

It also speeds up the %s format for get_all_args (at least the second
time a certain string is used) since the function checking for null
characters can now use the fields.

Currently most string operations simply reset the string to unchecked,
as an optimization they could copy the ranges/flag as appropriate.

The + operator already does keep track of the flags and ranges.

For wide-strings the min/max value is somewhat less correct, since
it's saved in a single byte. But '0' still works (you get string(0..X)
for strings with 0, and string(1..X) for strings without 0 but with
any other character from the first 255).

1555:    PCHARP buf;    ptrdiff_t tmp;    int max_shift=0; -  +  unsigned char tmp_flags, tmp_min, tmp_max;    if(args==1) return;       size=0;
1579:    }       tmp=sp[-args].u.string->len; +  tmp_flags = sp[-args].u.string->flags; +  tmp_min = sp[-args].u.string->min; +  tmp_max = sp[-args].u.string->max; +     r=new_realloc_shared_string(sp[-args].u.string,size,max_shift); -  +  +  r->flags |= tmp_flags & ~15; +  r->min = tmp_min; +  r->max = tmp_max; +     mark_free_svalue (sp - args);    buf=MKPCHARP_STR_OFF(r,tmp);    for(e=-args+1;e<0;e++)    { -  +  if( sp[e].u.string->len ) +  { +  update_flags_for_add( r, sp[e].u.string );    pike_string_cpy(buf,sp[e].u.string);    INC_PCHARP(buf,sp[e].u.string->len);    } -  +  }    SET_SVAL(sp[-args], T_STRING, 0, string, low_end_shared_string(r)); -  for(e=-args+1;e<0;e++) free_string(sp[e].u.string); +  +  for(e=-args+1;e<0;e++) +  free_string(sp[e].u.string); +     sp-=args-1;       break;