mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 23:15:58 +00:00
perf(json): count long unescaped ASCII strings without a JS loop (#12244)
* perf(json): count long unescaped ASCII strings without a JS loop * perf(json): count unescaped UTF-8 prefixes without rescanning --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
1 parent
4aeeb7e4fb
commit
ae44fa4ece
2 files changed
+29
-1
No files matched your search
@@ -42,3 +42,16 @@ it("counts adjacent surrogates, escapes and multibyte text as native JSON encode
|
||||
}
|
||||
expect(mismatches).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves exact length and budget overflow for long path-like strings", () => {
|
||||
const path = "fixtures/segment-0123456789/".repeat(80);
|
||||
for (const tail of ["", '"', "\\", "\n", "é𐐷", 'é"𐐷', "\ud800"]) {
|
||||
const value = path + tail;
|
||||
const expected = Buffer.byteLength(JSON.stringify(value));
|
||||
expect(jsonStringByteLength(value, expected)).toBe(expected);
|
||||
expect(jsonStringByteLength(value, expected - 1)).toBeGreaterThan(
|
||||
expected - 1,
|
||||
);
|
||||
expect(jsonStringByteLength(value, 128)).toBeGreaterThan(128);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user