From 5aed763bc1faeb00cdef1473587448c03b75edb3 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 28 Jul 2017 10:09:48 +0200 Subject: Move forward and copy memory when necessary, not for every char. --- document/src/vespa/document/base/fieldpath.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'document') diff --git a/document/src/vespa/document/base/fieldpath.cpp b/document/src/vespa/document/base/fieldpath.cpp index 0d43413e696..6625f9ae2a5 100644 --- a/document/src/vespa/document/base/fieldpath.cpp +++ b/document/src/vespa/document/base/fieldpath.cpp @@ -145,23 +145,25 @@ vespalib::string FieldPathEntry::parseKey(vespalib::stringref & key) if ((c < e) && (c[0] == '{')) { for(c++;(c < e) && isspace(c[0]); c++); if ((c < e) && (c[0] == '"')) { - for (c++; (c < e) && (c[0] != '"'); c++) { + const char * start = ++c; + for (; (c < e) && (c[0] != '"'); c++) { if (c[0] == '\\') { - c++; - } - if (c < e) { - v += c[0]; + v.append(start, c-start); + start = ++c; } } + v.append(start, c-start); if ((c < e) && (c[0] == '"')) { c++; } else { throw IllegalArgumentException(make_string("Escaped key '%s' is incomplete. No matching '\"'", key.c_str()), VESPA_STRLOC); } } else { - for (;(c < e) && (c[0] != '}'); c++) { - v += c[0]; + const char * start = c; + while ((c < e) && (c[0] != '}')) { + c++; } + v.append(start, c-start); } for(;(c < e) && isspace(c[0]); c++); if ((c < e) && (c[0] == '}')) { -- cgit v1.2.3