From ff23340fe2983b1f034b0e156807b328417d2310 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 18 Feb 2011 01:56:10 -0800 Subject: [PATCH] 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. --- src/upb_string.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/upb_string.c b/src/upb_string.c index e6ea5893a5..81b152dc70 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;