Fix efficiency bug for major (50% performance improvement!

There was a bug with string referencing that prevented
strings from being recycled as often as they ought to be.
pull/13171/head
Joshua Haberman 14 years ago
parent e75cff570c
commit ff23340fe2
  1. 5
      src/upb_string.c

@ -73,6 +73,11 @@ void upb_string_substr(upb_string *str, upb_string *target_str,
upb_strlen_t start, upb_strlen_t len) { upb_strlen_t start, upb_strlen_t len) {
if(str->ptr) *(char*)0 = 0; if(str->ptr) *(char*)0 = 0;
assert(str->ptr == NULL); assert(str->ptr == NULL);
assert(start + len <= upb_string_len(target_str));
if (target_str->src) {
start += (target_str->ptr - target_str->src->ptr);
target_str = target_str->src;
}
str->src = upb_string_getref(target_str); str->src = upb_string_getref(target_str);
str->ptr = upb_string_getrobuf(target_str) + start; str->ptr = upb_string_getrobuf(target_str) + start;
str->len = len; str->len = len;

Loading…
Cancel
Save