From c6a873617153984d904eb0c83fd226ae10bfec86 Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Sun, 30 Nov 2014 03:36:23 +0900 Subject: [PATCH] Use string::compare to improve performance. --- json11.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/json11.cpp b/json11.cpp index 6424554..88e376b 100644 --- a/json11.cpp +++ b/json11.cpp @@ -547,12 +547,11 @@ struct JsonParser { Json expect(const string &expected, Json res) { assert(i != 0); i--; - const string found = str.substr(i, expected.length()); - if (expected == found) { + if (str.compare(i, expected.length(), expected) == 0) { i += expected.length(); return res; } else { - return fail("parse error: expected " + expected + ", got " + found); + return fail("parse error: expected " + expected + ", got " + str.substr(i, expected.length())); } }