|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a
|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import "dart:_boxed_int"; |
5 | 6 | import "dart:_compact_hash" show createMapFromStringKeyValueListUnsafe;
|
6 | 7 | import "dart:_error_utils";
|
7 | 8 | import "dart:_internal"
|
@@ -176,6 +177,15 @@ class _JsonListener {
|
176 | 177 | this.value = value;
|
177 | 178 | }
|
178 | 179 |
|
| 180 | + @pragma('wasm:prefer-inline') |
| 181 | + void handleIntegerNumber(int value) { |
| 182 | + if (value.toWasmI64().leU(0xff.toWasmI64())) { |
| 183 | + handleNumber(_intBoxes256[value]); |
| 184 | + return; |
| 185 | + } |
| 186 | + handleNumber(value); |
| 187 | + } |
| 188 | + |
179 | 189 | void handleNumber(num value) {
|
180 | 190 | this.value = value;
|
181 | 191 | }
|
@@ -1433,7 +1443,7 @@ mixin _ChunkedJsonParser<T> on _ChunkedJsonParserState {
|
1433 | 1443 |
|
1434 | 1444 | void finishChunkNumber(int state, int start, int end) {
|
1435 | 1445 | if (state == NUM_ZERO) {
|
1436 |
| - listener.handleNumber(0); |
| 1446 | + listener.handleIntegerNumber(0); |
1437 | 1447 | numberBuffer.clear();
|
1438 | 1448 | return;
|
1439 | 1449 | }
|
@@ -1578,7 +1588,7 @@ mixin _ChunkedJsonParser<T> on _ChunkedJsonParserState {
|
1578 | 1588 | if (!isDouble) {
|
1579 | 1589 | int bitFlag = -(sign + 1) >> 1; // 0 if sign == -1, -1 if sign == 1
|
1580 | 1590 | // Negate if bitFlag is -1 by doing ~intValue + 1
|
1581 |
| - listener.handleNumber((intValue ^ bitFlag) - bitFlag); |
| 1591 | + listener.handleIntegerNumber((intValue ^ bitFlag) - bitFlag); |
1582 | 1592 | return position;
|
1583 | 1593 | }
|
1584 | 1594 | // Double values at or above this value (2 ** 53) may have lost precision.
|
@@ -2795,3 +2805,38 @@ double _jsParseFloat(String string) => JS<double>(
|
2795 | 2805 | '(s) => parseFloat(s)',
|
2796 | 2806 | jsStringFromDartString(string).toExternRef,
|
2797 | 2807 | );
|
| 2808 | + |
| 2809 | +const ImmutableWasmArray<BoxedInt> _intBoxes256 = ImmutableWasmArray.literal([ |
| 2810 | + 0, 1, 2, 3, 4, 5, 6, 7, // |
| 2811 | + 8, 9, 10, 11, 12, 13, 14, 15, // |
| 2812 | + 16, 17, 18, 19, 20, 21, 22, 23, // |
| 2813 | + 24, 25, 26, 27, 28, 29, 30, 31, // |
| 2814 | + 32, 33, 34, 35, 36, 37, 38, 39, // |
| 2815 | + 40, 41, 42, 43, 44, 45, 46, 47, // |
| 2816 | + 48, 49, 50, 51, 52, 53, 54, 55, // |
| 2817 | + 56, 57, 58, 59, 60, 61, 62, 63, // |
| 2818 | + 64, 65, 66, 67, 68, 69, 70, 71, // |
| 2819 | + 72, 73, 74, 75, 76, 77, 78, 79, // |
| 2820 | + 80, 81, 82, 83, 84, 85, 86, 87, // |
| 2821 | + 88, 89, 90, 91, 92, 93, 94, 95, // |
| 2822 | + 96, 97, 98, 99, 100, 101, 102, 103, // |
| 2823 | + 104, 105, 106, 107, 108, 109, 110, 111, // |
| 2824 | + 112, 113, 114, 115, 116, 117, 118, 119, // |
| 2825 | + 120, 121, 122, 123, 124, 125, 126, 127, // |
| 2826 | + 128, 129, 130, 131, 132, 133, 134, 135, // |
| 2827 | + 136, 137, 138, 139, 140, 141, 142, 143, // |
| 2828 | + 144, 145, 146, 147, 148, 149, 150, 151, // |
| 2829 | + 152, 153, 154, 155, 156, 157, 158, 159, // |
| 2830 | + 160, 161, 162, 163, 164, 165, 166, 167, // |
| 2831 | + 168, 169, 170, 171, 172, 173, 174, 175, // |
| 2832 | + 176, 177, 178, 179, 180, 181, 182, 183, // |
| 2833 | + 184, 185, 186, 187, 188, 189, 190, 191, // |
| 2834 | + 192, 193, 194, 195, 196, 197, 198, 199, // |
| 2835 | + 200, 201, 202, 203, 204, 205, 206, 207, // |
| 2836 | + 208, 209, 210, 211, 212, 213, 214, 215, // |
| 2837 | + 216, 217, 218, 219, 220, 221, 222, 223, // |
| 2838 | + 224, 225, 226, 227, 228, 229, 230, 231, // |
| 2839 | + 232, 233, 234, 235, 236, 237, 238, 239, // |
| 2840 | + 240, 241, 242, 243, 244, 245, 246, 247, // |
| 2841 | + 248, 249, 250, 251, 252, 253, 254, 255, // |
| 2842 | +]); |
0 commit comments