Use string::compare to improve performance.
parent
6de4c29e76
commit
c6a8736171
|
@ -547,12 +547,11 @@ struct JsonParser {
|
||||||
Json expect(const string &expected, Json res) {
|
Json expect(const string &expected, Json res) {
|
||||||
assert(i != 0);
|
assert(i != 0);
|
||||||
i--;
|
i--;
|
||||||
const string found = str.substr(i, expected.length());
|
if (str.compare(i, expected.length(), expected) == 0) {
|
||||||
if (expected == found) {
|
|
||||||
i += expected.length();
|
i += expected.length();
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
return fail("parse error: expected " + expected + ", got " + found);
|
return fail("parse error: expected " + expected + ", got " + str.substr(i, expected.length()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue