json-as 1.3.7 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +1 -1
  3. package/assembly/deserialize/index/arbitrary.ts +2 -2
  4. package/assembly/deserialize/index/array.ts +29 -14
  5. package/assembly/deserialize/index/bool.ts +1 -1
  6. package/assembly/deserialize/index/date.ts +1 -1
  7. package/assembly/deserialize/index/float.ts +40 -1
  8. package/assembly/deserialize/index/integer.ts +3 -3
  9. package/assembly/deserialize/index/map.ts +1 -1
  10. package/assembly/deserialize/index/object.ts +1 -1
  11. package/assembly/deserialize/index/raw.ts +1 -1
  12. package/assembly/deserialize/index/set.ts +1 -1
  13. package/assembly/deserialize/index/staticarray.ts +4 -1
  14. package/assembly/deserialize/index/string.ts +28 -3
  15. package/assembly/deserialize/index/struct.ts +1 -1
  16. package/assembly/deserialize/index/typedarray.ts +25 -15
  17. package/assembly/deserialize/index/unsigned.ts +3 -3
  18. package/assembly/deserialize/index.ts +1 -0
  19. package/assembly/deserialize/naive/array/bool.ts +68 -0
  20. package/assembly/deserialize/naive/array/float.ts +63 -0
  21. package/assembly/deserialize/{simple → naive}/array/generic.ts +1 -2
  22. package/assembly/deserialize/naive/array/integer.ts +86 -0
  23. package/assembly/deserialize/{simple → naive}/array/map.ts +0 -1
  24. package/assembly/deserialize/{simple → naive}/array/object.ts +0 -1
  25. package/assembly/deserialize/naive/array/string.ts +69 -0
  26. package/assembly/deserialize/{simple → naive}/array/struct.ts +0 -1
  27. package/assembly/deserialize/{simple → naive}/array.ts +6 -11
  28. package/assembly/deserialize/naive/float.ts +135 -0
  29. package/assembly/deserialize/{simple → naive}/integer.ts +2 -2
  30. package/assembly/deserialize/{simple → naive}/map.ts +12 -6
  31. package/assembly/deserialize/{simple → naive}/object.ts +4 -7
  32. package/assembly/deserialize/{simple → naive}/set.ts +12 -27
  33. package/assembly/deserialize/{simple → naive}/staticarray/array.ts +1 -1
  34. package/assembly/deserialize/{simple → naive}/staticarray/bool.ts +1 -1
  35. package/assembly/deserialize/{simple → naive}/staticarray/float.ts +1 -1
  36. package/assembly/deserialize/{simple → naive}/staticarray/integer.ts +1 -1
  37. package/assembly/deserialize/{simple → naive}/staticarray/struct.ts +1 -2
  38. package/assembly/deserialize/{simple → naive}/staticarray.ts +4 -4
  39. package/assembly/deserialize/naive/string.ts +199 -0
  40. package/assembly/deserialize/{simple → naive}/typedarray.ts +4 -4
  41. package/assembly/deserialize/{simple → naive}/unsigned.ts +2 -2
  42. package/assembly/deserialize/simd/array/integer.ts +19 -19
  43. package/assembly/deserialize/simd/float.ts +303 -0
  44. package/assembly/deserialize/simd/string.ts +233 -108
  45. package/assembly/deserialize/swar/array/arbitrary.ts +6 -2
  46. package/assembly/deserialize/swar/array/array.ts +14 -7
  47. package/assembly/deserialize/swar/array/bool.ts +8 -3
  48. package/assembly/deserialize/swar/array/box.ts +6 -2
  49. package/assembly/deserialize/swar/array/float.ts +282 -6
  50. package/assembly/deserialize/swar/array/generic.ts +6 -2
  51. package/assembly/deserialize/swar/array/integer.ts +81 -74
  52. package/assembly/deserialize/swar/array/map.ts +6 -2
  53. package/assembly/deserialize/swar/array/object.ts +24 -32
  54. package/assembly/deserialize/swar/array/raw.ts +6 -2
  55. package/assembly/deserialize/swar/array/shared.ts +32 -8
  56. package/assembly/deserialize/swar/array/string.ts +127 -10
  57. package/assembly/deserialize/swar/array/struct.ts +45 -11
  58. package/assembly/deserialize/swar/array.ts +2 -56
  59. package/assembly/deserialize/swar/float.ts +304 -0
  60. package/assembly/deserialize/swar/string.ts +119 -104
  61. package/assembly/deserialize/swar/typedarray.ts +224 -0
  62. package/assembly/index.ts +203 -293
  63. package/assembly/serialize/index/array.ts +1 -1
  64. package/assembly/serialize/index/bool.ts +1 -1
  65. package/assembly/serialize/index/date.ts +1 -1
  66. package/assembly/serialize/index/float.ts +1 -1
  67. package/assembly/serialize/index/integer.ts +1 -1
  68. package/assembly/serialize/index/map.ts +1 -1
  69. package/assembly/serialize/index/raw.ts +1 -1
  70. package/assembly/serialize/index/set.ts +1 -1
  71. package/assembly/serialize/index/staticarray.ts +1 -1
  72. package/assembly/serialize/index/string.ts +1 -1
  73. package/assembly/serialize/index/struct.ts +1 -1
  74. package/assembly/serialize/index/typedarray.ts +2 -11
  75. package/assembly/serialize/index.ts +1 -0
  76. package/assembly/serialize/{simple → naive}/array.ts +87 -0
  77. package/assembly/serialize/{simple → naive}/string.ts +1 -1
  78. package/assembly/serialize/swar/string.ts +0 -139
  79. package/assembly/util/dragonbox.ts +10 -3
  80. package/assembly/util/itoa-fast.ts +29 -18
  81. package/assembly/util/scanValueEnd.ts +78 -0
  82. package/assembly/util/scientific.ts +132 -0
  83. package/lib/as-bs.ts +14 -1
  84. package/package.json +14 -13
  85. package/transform/lib/index.d.ts +4 -0
  86. package/transform/lib/index.d.ts.map +1 -1
  87. package/transform/lib/index.js +155 -238
  88. package/transform/lib/index.js.map +1 -1
  89. package/assembly/deserialize/simple/arbitrary.ts +0 -30
  90. package/assembly/deserialize/simple/array/bool.ts +0 -48
  91. package/assembly/deserialize/simple/array/float.ts +0 -55
  92. package/assembly/deserialize/simple/array/integer.ts +0 -33
  93. package/assembly/deserialize/simple/array/string.ts +0 -29
  94. package/assembly/deserialize/simple/float.ts +0 -206
  95. package/assembly/deserialize/simple/string.ts +0 -45
  96. package/assembly/serialize/simple/arbitrary.ts +0 -79
  97. package/assembly/serialize/simple/object.ts +0 -42
  98. /package/assembly/deserialize/{simple → naive}/array/arbitrary.ts +0 -0
  99. /package/assembly/deserialize/{simple → naive}/array/array.ts +0 -0
  100. /package/assembly/deserialize/{simple → naive}/array/box.ts +0 -0
  101. /package/assembly/deserialize/{simple → naive}/array/raw.ts +0 -0
  102. /package/assembly/deserialize/{simple → naive}/bool.ts +0 -0
  103. /package/assembly/deserialize/{simple → naive}/date.ts +0 -0
  104. /package/assembly/deserialize/{simple → naive}/raw.ts +0 -0
  105. /package/assembly/deserialize/{simple → naive}/staticarray/string.ts +0 -0
  106. /package/assembly/deserialize/{simple → naive}/struct.ts +0 -0
  107. /package/assembly/serialize/{simple → naive}/bool.ts +0 -0
  108. /package/assembly/serialize/{simple → naive}/date.ts +0 -0
  109. /package/assembly/serialize/{simple → naive}/float.ts +0 -0
  110. /package/assembly/serialize/{simple → naive}/integer.ts +0 -0
  111. /package/assembly/serialize/{simple → naive}/map.ts +0 -0
  112. /package/assembly/serialize/{simple → naive}/raw.ts +0 -0
  113. /package/assembly/serialize/{simple → naive}/set.ts +0 -0
  114. /package/assembly/serialize/{simple → naive}/staticarray.ts +0 -0
  115. /package/assembly/serialize/{simple → naive}/struct.ts +0 -0
  116. /package/assembly/serialize/{simple → naive}/typedarray.ts +0 -0
@@ -0,0 +1,69 @@
1
+ import { JSON } from "../../..";
2
+ import {
3
+ COMMA,
4
+ BRACKET_LEFT,
5
+ BRACKET_RIGHT,
6
+ NULL_WORD_U64,
7
+ QUOTE,
8
+ } from "../../../custom/chars";
9
+ import { isSpace, scanStringEnd } from "../../../util";
10
+
11
+ /**
12
+ * Strict string-array deserializer (`string[]` / `(string | null)[]`).
13
+ *
14
+ * Enforces RFC 8259 array structure: `[`-framed, single-comma separated, no
15
+ * leading / trailing / doubled commas, and each element must be a quoted string
16
+ * (or the literal `null` for a nullable element type). Element contents are
17
+ * validated by `deserializeString_NAIVE` (via `JSON.__deserialize`). Throws on
18
+ * any deviation.
19
+ */
20
+ export function deserializeStringArray_NAIVE(
21
+ srcStart: usize,
22
+ srcEnd: usize,
23
+ dst: usize,
24
+ ): string[] {
25
+ const out = changetype<string[]>(
26
+ dst || changetype<usize>(instantiate<string[]>()),
27
+ );
28
+ out.length = 0; // dst may arrive pre-sized; re-parse from empty via push
29
+
30
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
31
+ while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2;
32
+ if (srcStart >= srcEnd || load<u16>(srcStart) != BRACKET_LEFT)
33
+ throw new Error("Invalid JSON array: expected '['");
34
+ if (load<u16>(srcEnd - 2) != BRACKET_RIGHT)
35
+ throw new Error("Invalid JSON array: expected ']'");
36
+ srcStart += 2; // past '['
37
+ srcEnd -= 2; // before ']'
38
+
39
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
40
+ if (srcStart >= srcEnd) return out;
41
+
42
+ while (true) {
43
+ const code = load<u16>(srcStart);
44
+ if (code == QUOTE) {
45
+ const closing = scanStringEnd(srcStart, srcEnd);
46
+ if (closing >= srcEnd)
47
+ throw new Error("Invalid JSON array: unterminated string");
48
+ out.push(JSON.__deserialize<string>(srcStart, closing + 2));
49
+ srcStart = closing + 2;
50
+ } else if (srcStart + 8 <= srcEnd && load<u64>(srcStart) == NULL_WORD_U64) {
51
+ // `(string | null)[]` element
52
+ out.push(changetype<string>(0));
53
+ srcStart += 8;
54
+ } else {
55
+ throw new Error("Invalid JSON array: expected string");
56
+ }
57
+
58
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
59
+ if (srcStart >= srcEnd) break;
60
+ if (load<u16>(srcStart) != COMMA)
61
+ throw new Error("Invalid JSON array: expected ',' or ']'");
62
+ srcStart += 2;
63
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
64
+ if (srcStart >= srcEnd)
65
+ throw new Error("Invalid JSON array: trailing comma");
66
+ }
67
+
68
+ return out;
69
+ }
@@ -18,7 +18,6 @@ export function deserializeStructArray<T extends unknown[]>(
18
18
  let lastIndex: usize = 0;
19
19
  let depth: u32 = 0;
20
20
 
21
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
22
21
  while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2;
23
22
 
24
23
  if (srcStart - srcEnd == 0)
@@ -2,20 +2,15 @@ import { JSON } from "../..";
2
2
  import { deserializeArbitraryArray } from "./array/arbitrary";
3
3
  import { deserializeArrayArray } from "./array/array";
4
4
  import { deserializeBooleanArray } from "./array/bool";
5
- import { deserializeFloatArray } from "./array/float";
5
+ import { deserializeFloatArray_NAIVE } from "./array/float";
6
6
  import { deserializeGenericArray } from "./array/generic";
7
- import { deserializeIntegerArray } from "./array/integer";
7
+ import { deserializeIntegerArray_NAIVE } from "./array/integer";
8
8
  import { deserializeMapArray } from "./array/map";
9
9
  import { deserializeStructArray } from "./array/struct";
10
- import { deserializeStringArray } from "./array/string";
10
+ import { deserializeStringArray_NAIVE } from "./array/string";
11
11
  import { deserializeObjectArray } from "./array/object";
12
12
  import { deserializeBoxArray } from "./array/box";
13
13
  import { deserializeRawArray } from "./array/raw";
14
- export {
15
- deserializeArrayField,
16
- deserializeArrayField as deserializeArrayField_SWAR,
17
- } from "../swar/array";
18
-
19
14
  // @ts-ignore: Decorator valid here
20
15
  export function deserializeArray<T extends unknown[]>(
21
16
  srcStart: usize,
@@ -23,16 +18,16 @@ export function deserializeArray<T extends unknown[]>(
23
18
  dst: usize,
24
19
  ): T {
25
20
  if (isString<valueof<T>>()) {
26
- return <T>deserializeStringArray(srcStart, srcEnd, dst);
21
+ return <T>deserializeStringArray_NAIVE(srcStart, srcEnd, dst);
27
22
  } else if (isBoolean<valueof<T>>()) {
28
23
  // @ts-ignore
29
24
  return deserializeBooleanArray<T>(srcStart, srcEnd, dst);
30
25
  } else if (isInteger<valueof<T>>()) {
31
26
  // @ts-ignore
32
- return deserializeIntegerArray<T>(srcStart, srcEnd, dst);
27
+ return deserializeIntegerArray_NAIVE<T>(srcStart, srcEnd, dst);
33
28
  } else if (isFloat<valueof<T>>()) {
34
29
  // @ts-ignore
35
- return deserializeFloatArray<T>(srcStart, srcEnd, dst);
30
+ return deserializeFloatArray_NAIVE<T>(srcStart, srcEnd, dst);
36
31
  } else if (isArray<valueof<T>>()) {
37
32
  // @ts-ignore: type
38
33
  return deserializeArrayArray<T>(srcStart, srcEnd, dst);
@@ -0,0 +1,135 @@
1
+ import { ptrToStr } from "../../util/ptrToStr";
2
+ import { isSpace } from "../../util";
3
+
4
+ // Strict RFC 8259 number-grammar check over [srcStart, srcEnd) (surrounding
5
+ // whitespace tolerated). Throws on any deviation: leading zeros, a bare `-`, a
6
+ // fraction / exponent with no digits, a `+` sign, hex, Inf/NaN, or trailing
7
+ // garbage. f64.parse alone is lenient (parses a numeric prefix and ignores the
8
+ // rest), so this guard is what makes the naive value path reject malformed
9
+ // numbers like `0e`, `-01`, `1.`, `2.e3`, `0x42`.
10
+ // @ts-ignore: inline
11
+ @inline function validateJSONNumber(srcStart: usize, srcEnd: usize): void {
12
+ let ptr = srcStart;
13
+ while (ptr < srcEnd && isSpace(load<u16>(ptr))) ptr += 2;
14
+ let end = srcEnd;
15
+ while (end > ptr && isSpace(load<u16>(end - 2))) end -= 2;
16
+ if (ptr >= end) throw new Error("Invalid JSON number: empty");
17
+
18
+ if (load<u16>(ptr) == 45) ptr += 2; // optional minus
19
+ if (ptr >= end) throw new Error("Invalid JSON number: bare '-'");
20
+
21
+ // Library extension (non-RFC, intentionally supported + tested): the literals
22
+ // NaN / Infinity / -Infinity. Hand these to f64.parse without strict checking.
23
+ const lead = load<u16>(ptr);
24
+ if (lead == 78 || lead == 110 || lead == 73 || lead == 105) return; // N n I i
25
+
26
+ // integer part: lone 0, or [1-9] digit*
27
+ const first = load<u16>(ptr);
28
+ if (first == 48) {
29
+ ptr += 2;
30
+ if (ptr < end && <u32>(load<u16>(ptr) - 48) <= 9)
31
+ throw new Error("Invalid JSON number: leading zero");
32
+ } else if (<u32>(first - 48) <= 9) {
33
+ ptr += 2;
34
+ while (ptr < end && <u32>(load<u16>(ptr) - 48) <= 9) ptr += 2;
35
+ } else {
36
+ throw new Error("Invalid JSON number: expected digit");
37
+ }
38
+
39
+ // optional fraction: '.' digit+
40
+ if (ptr < end && load<u16>(ptr) == 46) {
41
+ ptr += 2;
42
+ if (ptr >= end || <u32>(load<u16>(ptr) - 48) > 9)
43
+ throw new Error("Invalid JSON number: fraction needs a digit");
44
+ while (ptr < end && <u32>(load<u16>(ptr) - 48) <= 9) ptr += 2;
45
+ }
46
+
47
+ // optional exponent: ('e'|'E') ['+'|'-'] digit+
48
+ if (ptr < end) {
49
+ const e = load<u16>(ptr);
50
+ if (e == 101 || e == 69) {
51
+ ptr += 2;
52
+ if (ptr < end) {
53
+ const sign = load<u16>(ptr);
54
+ if (sign == 43 || sign == 45) ptr += 2;
55
+ }
56
+ if (ptr >= end || <u32>(load<u16>(ptr) - 48) > 9)
57
+ throw new Error("Invalid JSON number: exponent needs a digit");
58
+ while (ptr < end && <u32>(load<u16>(ptr) - 48) <= 9) ptr += 2;
59
+ }
60
+ }
61
+
62
+ if (ptr != end) throw new Error("Invalid JSON number: trailing characters");
63
+ }
64
+
65
+ // @ts-ignore: inline
66
+ @inline export function deserializeFloat_NAIVE<T>(
67
+ srcStart: usize,
68
+ srcEnd: usize,
69
+ ): T {
70
+ validateJSONNumber(srcStart, srcEnd);
71
+ // @ts-ignore
72
+ const type: T = 0;
73
+ // @ts-ignore
74
+ if (type instanceof f64) return f64.parse(ptrToStr(srcStart, srcEnd));
75
+ // @ts-ignore
76
+ return f32.parse(ptrToStr(srcStart, srcEnd));
77
+ }
78
+
79
+ // @ts-ignore: inline
80
+ @inline function scanFloatEnd(srcStart: usize, srcEnd: usize): usize {
81
+ let ptr = srcStart;
82
+ if (ptr < srcEnd && load<u16>(ptr) == 45) ptr += 2; // optional minus
83
+
84
+ while (ptr < srcEnd) {
85
+ const code = load<u16>(ptr);
86
+ if (<u32>code - 48 > 9) break;
87
+ ptr += 2;
88
+ }
89
+
90
+ if (ptr < srcEnd && load<u16>(ptr) == 46) {
91
+ ptr += 2;
92
+ while (ptr < srcEnd) {
93
+ const code = load<u16>(ptr);
94
+ if (<u32>code - 48 > 9) break;
95
+ ptr += 2;
96
+ }
97
+ }
98
+
99
+ if (ptr < srcEnd) {
100
+ const code = load<u16>(ptr);
101
+ if (code == 101 || code == 69) {
102
+ ptr += 2;
103
+ if (ptr < srcEnd) {
104
+ const sign = load<u16>(ptr);
105
+ if (sign == 45 || sign == 43) ptr += 2;
106
+ }
107
+ while (ptr < srcEnd) {
108
+ const code = load<u16>(ptr);
109
+ if (<u32>code - 48 > 9) break;
110
+ ptr += 2;
111
+ }
112
+ }
113
+ }
114
+
115
+ return ptr;
116
+ }
117
+
118
+ // @ts-ignore: inline
119
+ @inline export function deserializeFloatField_NAIVE<T extends number>(
120
+ srcStart: usize,
121
+ srcEnd: usize,
122
+ dstObj: usize,
123
+ dstOffset: usize = 0,
124
+ ): usize {
125
+ const fieldPtr = dstObj + dstOffset;
126
+ const end = scanFloatEnd(srcStart, srcEnd);
127
+
128
+ if (sizeof<T>() == sizeof<f32>()) {
129
+ store<f32>(fieldPtr, f32.parse(ptrToStr(srcStart, end)));
130
+ } else {
131
+ store<f64>(fieldPtr, f64.parse(ptrToStr(srcStart, end)));
132
+ }
133
+
134
+ return end;
135
+ }
@@ -1,7 +1,7 @@
1
1
  import { atoi } from "../../util/atoi";
2
2
 
3
3
  // @ts-ignore: inline
4
- @inline export function deserializeInteger<T>(
4
+ @inline export function deserializeInteger_NAIVE<T extends number>(
5
5
  srcStart: usize,
6
6
  srcEnd: usize,
7
7
  ): T {
@@ -9,7 +9,7 @@ import { atoi } from "../../util/atoi";
9
9
  }
10
10
 
11
11
  // @ts-ignore: inline
12
- @inline export function deserializeIntegerField<T extends number>(
12
+ @inline export function deserializeIntegerField_NAIVE<T extends number>(
13
13
  srcStart: usize,
14
14
  srcEnd: usize,
15
15
  dstObj: usize,
@@ -13,7 +13,7 @@ import {
13
13
  COLON,
14
14
  } from "../../custom/chars";
15
15
  import { isSpace, isUnescapedQuote, scanStringEnd } from "../../util";
16
- import { scanValueEnd } from "../swar/array/shared";
16
+ import { scanValueEnd } from "../../util/scanValueEnd";
17
17
 
18
18
  // @ts-ignore: Decorator is valid here
19
19
  @inline function deserializeMapKey<T>(start: usize, end: usize): T {
@@ -37,7 +37,6 @@ export function deserializeMap<T extends Map<any, any>>(
37
37
  let depth = 0;
38
38
  let lastIndex: usize = 0;
39
39
 
40
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
41
40
  while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2; // would like to optimize this later
42
41
 
43
42
  if (srcStart - srcEnd == 0)
@@ -231,7 +230,7 @@ export function deserializeMap<T extends Map<any, any>>(
231
230
  }
232
231
 
233
232
 
234
- @inline export function deserializeMapInto<T extends Map<any, any>>(
233
+ @inline function deserializeMapBody<T extends Map<any, any>>(
235
234
  srcStart: usize,
236
235
  srcEnd: usize,
237
236
  out: T,
@@ -241,10 +240,12 @@ export function deserializeMap<T extends Map<any, any>>(
241
240
  if (srcStart >= srcEnd || load<u16>(srcStart) != BRACE_LEFT)
242
241
  throw new Error("Failed to parse JSON!");
243
242
  srcStart += 2;
243
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
244
244
  if (srcStart >= srcEnd) throw new Error("Failed to parse JSON!");
245
245
  if (load<u16>(srcStart) == BRACE_RIGHT) return srcStart + 2;
246
246
 
247
247
  while (srcStart < srcEnd) {
248
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
248
249
  if (load<u16>(srcStart) != QUOTE) break;
249
250
 
250
251
  const keyStart = srcStart + 2;
@@ -252,8 +253,10 @@ export function deserializeMap<T extends Map<any, any>>(
252
253
  if (keyEnd >= srcEnd) break;
253
254
 
254
255
  srcStart = keyEnd + 2;
256
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
255
257
  if (srcStart >= srcEnd || load<u16>(srcStart) != COLON) break;
256
258
  srcStart += 2;
259
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
257
260
 
258
261
  const valueEnd = scanValueEnd(srcStart, srcEnd);
259
262
  if (!valueEnd || valueEnd <= srcStart) break;
@@ -265,10 +268,12 @@ export function deserializeMap<T extends Map<any, any>>(
265
268
  );
266
269
  srcStart = valueEnd;
267
270
 
271
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
268
272
  if (srcStart >= srcEnd) break;
269
273
  const code = load<u16>(srcStart);
270
274
  if (code == COMMA) {
271
275
  srcStart += 2;
276
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
272
277
  continue;
273
278
  }
274
279
  if (code == BRACE_RIGHT) return srcStart + 2;
@@ -285,10 +290,11 @@ export function deserializeMap<T extends Map<any, any>>(
285
290
  dstObj: usize,
286
291
  dstOffset: usize = 0,
287
292
  ): usize {
288
- let out = load<T>(dstObj, dstOffset);
293
+ const fieldPtr = dstObj + dstOffset;
294
+ let out = load<T>(fieldPtr);
289
295
  if (!changetype<usize>(out)) {
290
296
  out = changetype<T>(instantiate<T>());
291
- store<T>(dstObj, out, dstOffset);
297
+ store<T>(fieldPtr, out);
292
298
  }
293
- return deserializeMapInto<T>(srcStart, srcEnd, out);
299
+ return deserializeMapBody<T>(srcStart, srcEnd, out);
294
300
  }
@@ -15,12 +15,10 @@ import {
15
15
  } from "../../custom/chars";
16
16
  import { isSpace, isUnescapedQuote, scanStringEnd } from "../../util";
17
17
  import { ptrToStr } from "../../util/ptrToStr";
18
- import { deserializeString_SWAR } from "../swar/string";
19
- import { deserializeArbitrary } from "./arbitrary";
20
18
  import { deserializeArray } from "./array";
21
19
  import { deserializeBoolean } from "./bool";
22
- import { deserializeFloat } from "./float";
23
- import { deserializeString } from "./string";
20
+ import { deserializeFloat_NAIVE } from "./float";
21
+ import { deserializeString_NAIVE } from "./string";
24
22
 
25
23
  export function deserializeObject(
26
24
  srcStart: usize,
@@ -35,7 +33,6 @@ export function deserializeObject(
35
33
  let depth = 0;
36
34
  let lastIndex: usize = 0;
37
35
 
38
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
39
36
  while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2; // would like to optimize this later
40
37
 
41
38
  if (srcStart - srcEnd == 0)
@@ -84,7 +81,7 @@ export function deserializeObject(
84
81
  throw new Error("Unterminated string in JSON object");
85
82
  out.set(
86
83
  ptrToStr(keyStart, keyEnd),
87
- deserializeString(lastIndex, srcStart + 2),
84
+ deserializeString_NAIVE(lastIndex, srcStart + 2),
88
85
  );
89
86
  srcStart += 2;
90
87
  keyStart = 0;
@@ -98,7 +95,7 @@ export function deserializeObject(
98
95
  // console.log("Value (number): " + ptrToStr(lastIndex, srcStart));
99
96
  out.set(
100
97
  ptrToStr(keyStart, keyEnd),
101
- deserializeFloat<f64>(lastIndex, srcStart),
98
+ deserializeFloat_NAIVE<f64>(lastIndex, srcStart),
102
99
  );
103
100
  // while (isSpace(load<u16>((srcStart += 2)))) {
104
101
  // /* empty */
@@ -54,20 +54,17 @@ function deserializeSetDirect<T extends Set<any>>(
54
54
  srcStart: usize,
55
55
  srcEnd: usize,
56
56
  out: nonnull<T>,
57
- allowWhitespace: bool = false,
58
57
  ): usize {
59
58
  if (srcStart >= srcEnd || load<u16>(srcStart) != BRACKET_LEFT)
60
59
  throw new Error("Expected '[' at start of set");
61
60
 
62
61
  srcStart += 2;
63
- if (allowWhitespace)
64
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
62
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
65
63
  if (srcStart >= srcEnd) throw new Error("Unterminated set");
66
64
  if (load<u16>(srcStart) == BRACKET_RIGHT) return srcStart + 2;
67
65
 
68
66
  while (srcStart < srcEnd) {
69
- if (allowWhitespace)
70
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
67
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
71
68
  const code = load<u16>(srcStart);
72
69
 
73
70
  // @ts-ignore: type
@@ -97,12 +94,7 @@ function deserializeSetDirect<T extends Set<any>>(
97
94
  let ptr = srcStart + 2;
98
95
  while (ptr < srcEnd) {
99
96
  const next = load<u16>(ptr);
100
- if (
101
- next == COMMA ||
102
- next == BRACKET_RIGHT ||
103
- (allowWhitespace && isSpace(next))
104
- )
105
- break;
97
+ if (next == COMMA || next == BRACKET_RIGHT || isSpace(next)) break;
106
98
  ptr += 2;
107
99
  }
108
100
  // @ts-ignore: type
@@ -114,12 +106,7 @@ function deserializeSetDirect<T extends Set<any>>(
114
106
  let ptr = srcStart + 2;
115
107
  while (ptr < srcEnd) {
116
108
  const next = load<u16>(ptr);
117
- if (
118
- next == COMMA ||
119
- next == BRACKET_RIGHT ||
120
- (allowWhitespace && isSpace(next))
121
- )
122
- break;
109
+ if (next == COMMA || next == BRACKET_RIGHT || isSpace(next)) break;
123
110
  ptr += 2;
124
111
  }
125
112
  // @ts-ignore: type
@@ -136,14 +123,12 @@ function deserializeSetDirect<T extends Set<any>>(
136
123
  break;
137
124
  }
138
125
 
139
- if (allowWhitespace)
140
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
126
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
141
127
  if (srcStart >= srcEnd) break;
142
128
  const next = load<u16>(srcStart);
143
129
  if (next == COMMA) {
144
130
  srcStart += 2;
145
- if (allowWhitespace)
146
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
131
+ while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
147
132
  continue;
148
133
  }
149
134
  if (next == BRACKET_RIGHT) return srcStart + 2;
@@ -163,18 +148,17 @@ export function deserializeSet<T extends Set<any>>(
163
148
  );
164
149
  out.clear();
165
150
 
166
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
167
151
  while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2;
168
152
 
169
153
  if (srcStart >= srcEnd)
170
154
  throw new Error("Input string had zero length or was all whitespace");
171
- const end = deserializeSetDirect<T>(srcStart, srcEnd, out, true);
155
+ const end = deserializeSetDirect<T>(srcStart, srcEnd, out);
172
156
  if (end != srcEnd) throw new Error("Expected ']' at end of set");
173
157
  return out;
174
158
  }
175
159
 
176
160
  // @ts-expect-error: Decorator valid here
177
- @inline export function deserializeSetInto<T extends Set<any>>(
161
+ @inline function deserializeSetBody<T extends Set<any>>(
178
162
  srcStart: usize,
179
163
  srcEnd: usize,
180
164
  out: T,
@@ -190,10 +174,11 @@ export function deserializeSet<T extends Set<any>>(
190
174
  dstObj: usize,
191
175
  dstOffset: usize = 0,
192
176
  ): usize {
193
- let out = load<T>(dstObj, dstOffset);
177
+ const fieldPtr = dstObj + dstOffset;
178
+ let out = load<T>(fieldPtr);
194
179
  if (!changetype<usize>(out)) {
195
180
  out = changetype<T>(instantiate<T>());
196
- store<T>(dstObj, out, dstOffset);
181
+ store<T>(fieldPtr, out);
197
182
  }
198
- return deserializeSetInto<T>(srcStart, srcEnd, out);
183
+ return deserializeSetBody<T>(srcStart, srcEnd, out);
199
184
  }
@@ -19,7 +19,7 @@ export function deserializeStaticArrayArray<T extends StaticArray<any>>(
19
19
  ptr += 2;
20
20
  }
21
21
 
22
- const outSize = count << (alignof<valueof<T>>());
22
+ const outSize = count * sizeof<valueof<T>>();
23
23
  const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
24
24
 
25
25
  // Second pass: populate values
@@ -20,7 +20,7 @@ export function deserializeStaticArrayBoolean<T extends StaticArray<any>>(
20
20
  }
21
21
 
22
22
  // Allocate StaticArray with correct size
23
- const outSize = count << (alignof<valueof<T>>());
23
+ const outSize = count * sizeof<valueof<T>>();
24
24
  const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
25
25
 
26
26
  // Second pass: populate values
@@ -23,7 +23,7 @@ export function deserializeStaticArrayFloat<T extends StaticArray<any>>(
23
23
  ptr += 2;
24
24
  }
25
25
 
26
- const outSize = count << (alignof<valueof<T>>());
26
+ const outSize = count * sizeof<valueof<T>>();
27
27
  const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
28
28
 
29
29
  let index = 0;
@@ -22,7 +22,7 @@ export function deserializeStaticArrayInteger<T extends StaticArray<any>>(
22
22
  ptr += 2;
23
23
  }
24
24
 
25
- const outSize = count << (alignof<valueof<T>>());
25
+ const outSize = count * sizeof<valueof<T>>();
26
26
  const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
27
27
 
28
28
  // Second pass: populate values
@@ -12,7 +12,6 @@ export function deserializeStaticArrayStruct<T extends StaticArray<any>>(
12
12
  srcEnd: usize,
13
13
  dst: usize,
14
14
  ): T {
15
- while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
16
15
  while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2;
17
16
 
18
17
  if (srcStart - srcEnd == 0)
@@ -44,7 +43,7 @@ export function deserializeStaticArrayStruct<T extends StaticArray<any>>(
44
43
  }
45
44
 
46
45
  // Allocate StaticArray with correct size
47
- const outSize = count << (alignof<valueof<T>>());
46
+ const outSize = count * sizeof<valueof<T>>();
48
47
  const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
49
48
 
50
49
  // Second pass: populate values
@@ -4,18 +4,18 @@ import { deserializeArbitraryArray } from "./array/arbitrary";
4
4
  import { deserializeArrayArray } from "./array/array";
5
5
  import { deserializeBooleanArray } from "./array/bool";
6
6
  import { deserializeBoxArray } from "./array/box";
7
- import { deserializeFloatArray } from "./array/float";
8
- import { deserializeIntegerArray } from "./array/integer";
7
+ import { deserializeFloatArray_NAIVE } from "./array/float";
8
+ import { deserializeIntegerArray_NAIVE } from "./array/integer";
9
9
  import { deserializeMapArray } from "./array/map";
10
10
  import { deserializeObjectArray } from "./array/object";
11
11
  import { deserializeRawArray } from "./array/raw";
12
12
  import { deserializeStructArray } from "./array/struct";
13
- import { deserializeStringArray } from "./array/string";
13
+ import { deserializeStringArray_NAIVE } from "./array/string";
14
14
  import { deserializeStaticArrayBoolean } from "./staticarray/bool";
15
15
  import { deserializeStaticArrayFloat } from "./staticarray/float";
16
16
  import { deserializeStaticArrayInteger } from "./staticarray/integer";
17
17
  import { deserializeStaticArrayString } from "./staticarray/string";
18
- import { scanValueEnd } from "../swar/array/shared";
18
+ import { scanValueEnd } from "../../util/scanValueEnd";
19
19
 
20
20
 
21
21
  @inline function materializeStaticArray<T extends StaticArray<any>>(