diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2021-06-06 16:56:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-06 16:56:44 +0200 |
commit | 5bd77f29e5d07af10fe9a24062c3b5b4bb79f4bf (patch) | |
tree | 8174c49d3a2d948d708cf4f8372aa5c1b2e14cb4 /extensions/webidl/00_webidl.js | |
parent | 1fb2e23a6747a4f774e63639eb522cb34aadbf42 (diff) |
chore: optimize USVString webidl converters (#10865)
Diffstat (limited to 'extensions/webidl/00_webidl.js')
-rw-r--r-- | extensions/webidl/00_webidl.js | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/extensions/webidl/00_webidl.js b/extensions/webidl/00_webidl.js index 6fffa9319..ed777b8e5 100644 --- a/extensions/webidl/00_webidl.js +++ b/extensions/webidl/00_webidl.js @@ -331,29 +331,28 @@ converters.USVString = (V, opts) => { const S = converters.DOMString(V, opts); const n = S.length; - const U = []; + let U = ""; for (let i = 0; i < n; ++i) { const c = S.charCodeAt(i); if (c < 0xd800 || c > 0xdfff) { - U.push(String.fromCodePoint(c)); + U += String.fromCodePoint(c); } else if (0xdc00 <= c && c <= 0xdfff) { - U.push(String.fromCodePoint(0xfffd)); + U += String.fromCodePoint(0xfffd); } else if (i === n - 1) { - U.push(String.fromCodePoint(0xfffd)); + U += String.fromCodePoint(0xfffd); } else { const d = S.charCodeAt(i + 1); if (0xdc00 <= d && d <= 0xdfff) { const a = c & 0x3ff; const b = d & 0x3ff; - U.push(String.fromCodePoint((2 << 15) + (2 << 9) * a + b)); + U += String.fromCodePoint((2 << 15) + (2 << 9) * a + b); ++i; } else { - U.push(String.fromCodePoint(0xfffd)); + U += String.fromCodePoint(0xfffd); } } } - - return U.join(""); + return U; }; converters.object = (V, opts) => { |