mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +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;
|
const char* g_new_line_then_256_indent_bytes;
|
||||||
uint32_t g_bytes_per_indent_depth;
|
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;
|
wuffs_base__io_buffer g_dst;
|
||||||
|
|
||||||
uint32_t g_depth;
|
uint32_t g_depth;
|
||||||
@@ -252,7 +256,7 @@ flush_dst() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string //
|
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);
|
const uint8_t* p = static_cast<const uint8_t*>(s);
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
size_t i = g_dst.writer_length();
|
size_t i = g_dst.writer_length();
|
||||||
@@ -276,6 +280,17 @@ write_dst(const void* s, size_t n) {
|
|||||||
return "";
|
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 {
|
class Callbacks : public wuffs_aux::DecodeCborCallbacks {
|
||||||
@@ -612,8 +627,7 @@ class Callbacks : public wuffs_aux::DecodeCborCallbacks {
|
|||||||
|
|
||||||
std::string //
|
std::string //
|
||||||
main1(int argc, char** argv) {
|
main1(int argc, char** argv) {
|
||||||
g_dst = wuffs_base__ptr_u8__writer(
|
g_dst = wuffs_base__ptr_u8__writer(&g_dst_array[0], DST_BUFFER_ARRAY_SIZE);
|
||||||
&g_dst_array[0], (sizeof(g_dst_array) / sizeof(g_dst_array[0])));
|
|
||||||
g_depth = 0;
|
g_depth = 0;
|
||||||
g_ctx = context::none;
|
g_ctx = context::none;
|
||||||
g_wrote_to_dst = false;
|
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;
|
wuffs_base__io_buffer g_dst;
|
||||||
|
|
||||||
std::vector<uint32_t> g_quirks;
|
std::vector<uint32_t> g_quirks;
|
||||||
@@ -190,7 +194,7 @@ flush_dst() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string //
|
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);
|
const uint8_t* p = static_cast<const uint8_t*>(s);
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
size_t i = g_dst.writer_length();
|
size_t i = g_dst.writer_length();
|
||||||
@@ -213,6 +217,16 @@ write_dst(const void* s, size_t n) {
|
|||||||
return "";
|
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 {
|
class Callbacks : public wuffs_aux::DecodeJsonCallbacks {
|
||||||
@@ -298,8 +312,7 @@ class Callbacks : public wuffs_aux::DecodeJsonCallbacks {
|
|||||||
|
|
||||||
std::string //
|
std::string //
|
||||||
main1(int argc, char** argv) {
|
main1(int argc, char** argv) {
|
||||||
g_dst = wuffs_base__ptr_u8__writer(
|
g_dst = wuffs_base__ptr_u8__writer(&g_dst_array[0], DST_BUFFER_ARRAY_SIZE);
|
||||||
&g_dst_array[0], (sizeof(g_dst_array) / sizeof(g_dst_array[0])));
|
|
||||||
|
|
||||||
TRY(parse_flags(argc, argv));
|
TRY(parse_flags(argc, argv));
|
||||||
|
|
||||||
|
|||||||
@@ -818,10 +818,7 @@ flush_dst() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* //
|
const char* //
|
||||||
write_dst(const void* s, size_t n) {
|
write_dst_slow(const void* s, size_t n) {
|
||||||
if (g_suppress_write_dst > 0) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
const uint8_t* p = static_cast<const uint8_t*>(s);
|
const uint8_t* p = static_cast<const uint8_t*>(s);
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
size_t i = g_dst.writer_length();
|
size_t i = g_dst.writer_length();
|
||||||
@@ -848,6 +845,19 @@ write_dst(const void* s, size_t n) {
|
|||||||
return nullptr;
|
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 //
|
uint8_t //
|
||||||
|
|||||||
Reference in new issue
Block a user