Branch: Tag:

2014-12-04

2014-12-04 19:23:36 by Arne Goedeke <el@laramies.com>

use string range information to optimize utf8_to_string/string_to_utf8

1969:    ptrdiff_t i,j;    INT_TYPE extended = 0;    PCHARP src; +  INT32 min, max;       get_all_args("string_to_utf8", args, "%W.%i", &in, &extended);       len = in->len;    -  +  check_string_range(in, 1, &min, &max); +  +  if (min >= 0 && max <= 0x7f) { +  /* 7bit string -- already valid utf8. */ +  pop_n_elems(args - 1); +  return; +  } +     for(i=0,src=MKPCHARP_STR(in); i < in->len; INC_PCHARP(src,1),i++) {    unsigned INT32 c = EXTRACT_PCHARP(src);    if (c & ~0x7f) {
2115:    int shift = 0;    ptrdiff_t i,j=0;    INT_TYPE extended = 0; +  INT32 min, max;       get_all_args("utf8_to_string", args, "%S.%i", &in, &extended);    -  +  check_string_range(in, 1, &min, &max); +  +  if (min >= 0 && max <= 0x7f) { +  /* 7bit string -- already valid utf8. */ +  pop_n_elems(args - 1); +  return; +  } +     for(i=0; i < in->len; i++) {    unsigned int c = STR0(in)[i];    len++;