diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-02-18 01:56:10 -0800 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-02-18 01:56:10 -0800 |
commit | ff23340fe2983b1f034b0e156807b328417d2310 (patch) | |
tree | bbe90bf4ef35fc59c0f98a7fd798b3aaa9f58954 /src/upb_string.c | |
parent | e75cff570c23f2d140b4fdf4e242436f72c83fdc (diff) |
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.
Diffstat (limited to 'src/upb_string.c')
-rw-r--r-- | src/upb_string.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/upb_string.c b/src/upb_string.c index e6ea589..81b152d 100644 --- a/src/upb_string.c +++ b/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) { if(str->ptr) *(char*)0 = 0; 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->ptr = upb_string_getrobuf(target_str) + start; str->len = len; |