mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
querystring: reduce memory usage by Int8Array
PR-URL: https://github.com/nodejs/node/pull/34179 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
0dee49800d
commit
00b5ee6083
4 changed files with 14 additions and 10 deletions
|
@ -26,6 +26,7 @@
|
|||
const {
|
||||
Array,
|
||||
ArrayIsArray,
|
||||
Int8Array,
|
||||
MathAbs,
|
||||
NumberIsFinite,
|
||||
ObjectCreate,
|
||||
|
@ -54,7 +55,7 @@ const QueryString = module.exports = {
|
|||
decode: parse
|
||||
};
|
||||
|
||||
const unhexTable = [
|
||||
const unhexTable = new Int8Array([
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0 - 15
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16 - 31
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32 - 47
|
||||
|
@ -71,7 +72,7 @@ const unhexTable = [
|
|||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // ... 255
|
||||
];
|
||||
]);
|
||||
// A safe fast alternative to decodeURIComponent
|
||||
function unescapeBuffer(s, decodeSpaces) {
|
||||
const out = Buffer.allocUnsafe(s.length);
|
||||
|
@ -131,7 +132,7 @@ function qsUnescape(s, decodeSpaces) {
|
|||
// digits
|
||||
// alpha (uppercase)
|
||||
// alpha (lowercase)
|
||||
const noEscape = [
|
||||
const noEscape = new Int8Array([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
|
||||
0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 32 - 47
|
||||
|
@ -140,7 +141,7 @@ const noEscape = [
|
|||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 80 - 95
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 112 - 127
|
||||
];
|
||||
]);
|
||||
// QueryString.escape() replaces encodeURIComponent()
|
||||
// https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4
|
||||
function qsEscape(str) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue