mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
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:
1 parent
fc304139af
commit
6b86cbcb25
3 files changed
+49
-12
No files matched your search
@@ -137,7 +137,11 @@ static const char* g_usage =
|
||||
const char* g_new_line_then_256_indent_bytes;
|
||||
uint32_t g_bytes_per_indent_depth;
|
||||
|
||||
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;
|
||||
|
||||
uint32_t g_depth;
|
||||
@@ -252,7 +256,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();
|
||||
@@ -276,6 +280,17 @@ 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;
|
||||
g_wrote_to_dst = true;
|
||||
return "";
|
||||
}
|
||||
return write_dst_slow(s, n);
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
class Callbacks : public wuffs_aux::DecodeCborCallbacks {
|
||||
@@ -612,8 +627,7 @@ class Callbacks : public wuffs_aux::DecodeCborCallbacks {
|
||||
|
||||
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);
|
||||
g_depth = 0;
|
||||
g_ctx = context::none;
|
||||
g_wrote_to_dst = false;
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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 //
|
||||
|
||||
Reference in new issue
Block a user