From 771d4f9d98b10b2f950d1b780bc7f3a134c05457 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 5 Mar 2020 11:17:57 +1100 Subject: [PATCH] Add std/json lut_decimal_digits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old speed new speed delta wuffs_json_decode_1k/clang5 1.13GB/s ± 0% 1.12GB/s ± 1% -1.01% (p=0.002 n=10+10) wuffs_json_decode_21k_formatted/clang5 576MB/s ± 1% 595MB/s ± 1% +3.29% (p=0.000 n=10+10) wuffs_json_decode_26k_compact/clang5 873MB/s ± 1% 907MB/s ± 1% +3.81% (p=0.000 n=10+10) wuffs_json_decode_217k_stringy/clang5 727MB/s ± 0% 750MB/s ± 0% +3.14% (p=0.000 n=10+8) wuffs_json_decode_1k/gcc9 1.10GB/s ± 1% 1.11GB/s ± 1% +0.43% (p=0.035 n=10+10) wuffs_json_decode_21k_formatted/gcc9 628MB/s ± 0% 618MB/s ± 1% -1.59% (p=0.000 n=10+10) wuffs_json_decode_26k_compact/gcc9 892MB/s ± 0% 888MB/s ± 1% -0.43% (p=0.023 n=10+10) wuffs_json_decode_217k_stringy/gcc9 724MB/s ± 1% 733MB/s ± 1% +1.28% (p=0.000 n=10+10) --- release/c/wuffs-unsupported-snapshot.c | 23 +++++++++++++- std/json/common_consts.wuffs | 42 ++++++++++++++++++++++++++ std/json/decode_json.wuffs | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index cb70b3ba..3ee50672 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -19211,6 +19211,27 @@ static const uint8_t // 15, 15, 15, 15, }; +static const uint8_t // + wuffs_json__lut_decimal_digits[256] // + WUFFS_BASE__POTENTIALLY_UNUSED = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + static const uint8_t // wuffs_json__lut_hexadecimal_digits[256] // WUFFS_BASE__POTENTIALLY_UNUSED = { @@ -20333,7 +20354,7 @@ wuffs_json__decoder__decode_digits(wuffs_json__decoder* self, goto label__0__break; } v_c = wuffs_base__load_u8be__no_bounds_check(iop_a_src); - if ((v_c < 48) || (57 < v_c)) { + if (0 == wuffs_json__lut_decimal_digits[v_c]) { goto label__0__break; } if (v_n >= 99) { diff --git a/std/json/common_consts.wuffs b/std/json/common_consts.wuffs index 86b1619f..3cf4041e 100644 --- a/std/json/common_consts.wuffs +++ b/std/json/common_consts.wuffs @@ -230,6 +230,48 @@ pri const lut_classes array[256] base.u8[..= 0x0F] = [ // 8 9 A B C D E F ] +pri const lut_decimal_digits array[256] base.u8 = [ + // 0 1 2 3 4 5 6 7 + // 8 9 A B C D E F + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x08 ..= 0x0F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x10 ..= 0x17. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x18 ..= 0x1F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x20 ..= 0x27. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x28 ..= 0x2F. + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, // 0x30 ..= 0x37. '0'-'7'. + 0x88, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x38 ..= 0x3F. '8'-'9'. + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x40 ..= 0x47. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x48 ..= 0x4F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 ..= 0x57. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x58 ..= 0x5F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x60 ..= 0x67. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x68 ..= 0x6F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x70 ..= 0x77. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x78 ..= 0x7F. + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80 ..= 0x87. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x88 ..= 0x8F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x90 ..= 0x97. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x98 ..= 0x9F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA0 ..= 0xA7. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA8 ..= 0xAF. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB0 ..= 0xB7. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB8 ..= 0xBF. + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC0 ..= 0xC7. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC8 ..= 0xCF. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD0 ..= 0xD7. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD8 ..= 0xDF. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE0 ..= 0xE7. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE8 ..= 0xEF. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF0 ..= 0xF7. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF8 ..= 0xFF. + // 0 1 2 3 4 5 6 7 + // 8 9 A B C D E F +] + pri const lut_hexadecimal_digits array[256] base.u8 = [ // 0 1 2 3 4 5 6 7 // 8 9 A B C D E F diff --git a/std/json/decode_json.wuffs b/std/json/decode_json.wuffs index 7f3f4834..5364618d 100644 --- a/std/json/decode_json.wuffs +++ b/std/json/decode_json.wuffs @@ -974,7 +974,7 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 0xFF]) base break } c = args.src.peek_u8() - if (c < 0x30) or (0x39 < c) { + if 0x00 == lut_decimal_digits[c] { break } // Cap the maximum supported number length at an arbitrary value, 99.