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

+14 -4
View File
@@ -818,10 +818,7 @@ flush_dst() {
}
const char* //
write_dst(const void* s, size_t n) {
if (g_suppress_write_dst > 0) {
return nullptr;
}
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();
@@ -848,6 +845,19 @@ write_dst(const void* s, size_t n) {
return nullptr;
}
inline const char* //
write_dst(const void* s, size_t n) {
if (g_suppress_write_dst > 0) {
return nullptr;
} else 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;
g_wrote_to_dst = true;
return nullptr;
}
return write_dst_slow(s, n);
}
// ----
uint8_t //