Optimize example/jsonptr's write_dst

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-jsonptr < citylots.json > /dev/null
Before this commit:
real    0m1.949s
After:
real    0m1.863s
Ratio: 1.05x
This commit is contained in:
Nigel Tao committed 2020-08-19 15:53:06 +10:00
1 parent fc304139af
commit 6b86cbcb25
3 files changed
+49 -12

No files matched your search

+17 -4
View File
@@ -114,7 +114,11 @@ static const char* g_usage =
// ----
uint8_t g_dst_array[32768];
#ifndef DST_BUFFER_ARRAY_SIZE
#define DST_BUFFER_ARRAY_SIZE (32 * 1024)
#endif
uint8_t g_dst_array[DST_BUFFER_ARRAY_SIZE];
wuffs_base__io_buffer g_dst;
std::vector<uint32_t> g_quirks;
@@ -190,7 +194,7 @@ flush_dst() {
}
std::string //
write_dst(const void* s, size_t n) {
write_dst_slow(const void* s, size_t n) {
const uint8_t* p = static_cast<const uint8_t*>(s);
while (n > 0) {
size_t i = g_dst.writer_length();
@@ -213,6 +217,16 @@ write_dst(const void* s, size_t n) {
return "";
}
inline std::string //
write_dst(const void* s, size_t n) {
if (n <= (DST_BUFFER_ARRAY_SIZE - g_dst.meta.wi)) {
memcpy(g_dst.data.ptr + g_dst.meta.wi, s, n);
g_dst.meta.wi += n;
return "";
}
return write_dst_slow(s, n);
}
// ----
class Callbacks : public wuffs_aux::DecodeJsonCallbacks {
@@ -298,8 +312,7 @@ class Callbacks : public wuffs_aux::DecodeJsonCallbacks {
std::string //
main1(int argc, char** argv) {
g_dst = wuffs_base__ptr_u8__writer(
&g_dst_array[0], (sizeof(g_dst_array) / sizeof(g_dst_array[0])));
g_dst = wuffs_base__ptr_u8__writer(&g_dst_array[0], DST_BUFFER_ARRAY_SIZE);
TRY(parse_flags(argc, argv));