mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Have jsonfindptrs cache std::to_string(i)
On a mid-range x86_64 laptop, processing the 181 MiB citylots.json file from github.com/zemirco/sf-city-lots-json: $ time gen/bin/example-jsonfindptrs < citylots.json > /dev/null Before this commit: real 0m8.822s After: real 0m7.550s Ratio: 1.17x
This commit is contained in:
1 parent
8098d96113
commit
b6c01b3464
1 file changed
+7
-1
@@ -191,6 +191,9 @@ std::vector<uint32_t> g_quirks;
|
||||
|
||||
std::string g_dst;
|
||||
|
||||
// g_to_string_cache[i] caches the result of std::to_string(i).
|
||||
std::vector<std::string> g_to_string_cache;
|
||||
|
||||
struct {
|
||||
int remaining_argc;
|
||||
char** remaining_argv;
|
||||
@@ -362,7 +365,10 @@ print_json_pointers(JsonThing& jt, uint32_t depth) {
|
||||
case JsonThing::Kind::Array:
|
||||
g_dst += "/";
|
||||
for (size_t i = 0; i < jt.value.a.size(); i++) {
|
||||
g_dst += std::to_string(i);
|
||||
if (i >= g_to_string_cache.size()) {
|
||||
g_to_string_cache.push_back(std::to_string(i));
|
||||
}
|
||||
g_dst += g_to_string_cache[i];
|
||||
TRY(print_json_pointers(jt.value.a[i], depth));
|
||||
g_dst.resize(n + 1);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user