Use string::compare to improve performance.

mutable-v2
Masamitsu MURASE 2014-11-30 03:36:23 +09:00
parent 6de4c29e76
commit c6a8736171
1 changed files with 2 additions and 3 deletions

View File

@ -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()));
}
}