Commit 6d2c9612 authored by Krishna Kondaka's avatar Krishna Kondaka Committed by Facebook Github Bot

Fix folly::json perf issue

Summary: Original change to folly::json as part of D13038266/ was reverted due to performance regression in Android. This is modified version to keep track of lineNum while skipping white spaces.

Reviewed By: yfeldblum

Differential Revision: D13293197

fbshipit-source-id: 96d07946ae7430a182ff98f6dfd6d32e3a923991
parent 99cba475
......@@ -249,7 +249,25 @@ struct Input {
}
void skipWhitespace() {
range_ = folly::skipWhitespace(range_);
unsigned index = 0;
while (true) {
while (index < range_.size() && range_[index] == ' ') {
index++;
}
if (index < range_.size()) {
if (range_[index] == '\n') {
index++;
++lineNum_;
continue;
}
if (range_[index] == '\t' || range_[index] == '\r') {
index++;
continue;
}
}
break;
}
range_.advance(index);
storeCurrent();
}
......
......@@ -357,6 +357,16 @@ TEST(LogConfig, parseJsonErrors) {
parseLogConfigJson("[1, 2, 3]"),
LogConfigParseError,
"JSON config input must be an object");
EXPECT_THROW_RE(
parseLogConfigJson(
"{\n\"N\":\"X\",\n\"id\":\"1\",\n\"T\",:[\n\"A\",\n\"B\",\n]\n}\n"),
std::runtime_error,
"json parse error on line 3 near");
EXPECT_THROW_RE(
parseLogConfigJson(
"{\n\"N\":\"X\",\n\"id\":\"1\",\n\"T\":[\n\"A\",\n\"B\",\n\n}\n"),
std::runtime_error,
"json parse error on line 7 near");
EXPECT_THROW_RE(
parseLogConfigJson(""), std::runtime_error, "json parse error");
EXPECT_THROW_RE(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment