json: optimize number parsing for large number datasets - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 226d85203f7ea26dcc71c98e0fb7fe3ffb78176b
(DIR) parent 650481927d19d28d035d470bdedd2e2226e4dbd2
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Thu, 23 Sep 2021 18:31:00 +0200
json: optimize number parsing for large number datasets
Measured on OpenBSD and Voidlinux glibc (gcc and clang).
Not much difference on AMD Ryzen with GNUVoid Linux (glibc).
Tested and much difference on OpenBSD-current (laptop, older Intel CPU), 6.8
and 6.9 (older Intel Xeons).
Tested with json-testsuite, no differences (as intended).
Diffstat:
M json.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/json.c b/json.c
@@ -291,7 +291,8 @@ escchr:
while (1) {
c = GETNEXT();
if (c == EOF ||
- !c || !strchr("0123456789eE+-.", c) ||
+ (!isdigit(c) && c != 'e' && c != 'E' &&
+ c != '+' && c != '-' && c != '.') ||
p + 1 >= sizeof(pri)) {
pri[p] = '\0';
cb(nodes, depth + 1, pri);