GeezerVison is showing github.com — querystring: reduce memory usage by Int8Array · nodejs/node@e161249
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/querystring.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | Array, | | 5 | + Int8Array, | 5 | 6 | } = primordials; | 6 | 7 |
| 7 | 8 | const { ERR_INVALID_URI } = require('internal/errors').codes; | @@ -10,7 +11,7 @@ const hexTable = new Array(256); | 10 | 11 | for (let i = 0; i < 256; ++i) | 11 | 12 | hexTable[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase(); | 12 | 13 |
| 13 | | -const isHexTable = [ | | 14 | +const isHexTable = new Int8Array([ | 14 | 15 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15 | 15 | 16 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31 | 16 | 17 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32 - 47 | @@ -27,7 +28,7 @@ const isHexTable = [ | 27 | 28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 28 | 29 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 29 | 30 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // ... 256 | 30 | | -]; | | 31 | +]); | 31 | 32 |
| 32 | 33 | function encodeStr(str, noEscapeTable, hexTable) { | 33 | 34 | const len = str.length; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/url.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | Array, | | 5 | + Int8Array, | 5 | 6 | Number, | 6 | 7 | ObjectCreate, | 7 | 8 | ObjectDefineProperties, | @@ -817,7 +818,7 @@ function parseParams(qs) { | 817 | 818 |
| 818 | 819 | // Adapted from querystring's implementation. | 819 | 820 | // Ref: https://url.spec.whatwg.org/#concept-urlencoded-byte-serializer | 820 | | -const noEscape = [ | | 821 | +const noEscape = new Int8Array([ | 821 | 822 | /* | 822 | 823 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F | 823 | 824 | */ | @@ -829,7 +830,7 @@ const noEscape = [ | 829 | 830 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F | 830 | 831 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F | 831 | 832 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 0x70 - 0x7F | 832 | | -]; | | 833 | +]); | 833 | 834 |
| 834 | 835 | // Special version of hexTable that uses `+` for U+0020 SPACE. | 835 | 836 | const paramHexTable = hexTable.slice(); | |
Collapse file Copy file name to clipboardExpand all lines: lib/querystring.js +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 26 | 26 | const { | 27 | 27 | Array, | 28 | 28 | ArrayIsArray, | | 29 | + Int8Array, | 29 | 30 | MathAbs, | 30 | 31 | ObjectCreate, | 31 | 32 | ObjectKeys, | @@ -53,7 +54,7 @@ const QueryString = module.exports = { | 53 | 54 | decode: parse | 54 | 55 | }; | 55 | 56 |
| 56 | | -const unhexTable = [ | | 57 | +const unhexTable = new Int8Array([ | 57 | 58 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0 - 15 | 58 | 59 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16 - 31 | 59 | 60 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32 - 47 | @@ -70,7 +71,7 @@ const unhexTable = [ | 70 | 71 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 71 | 72 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 72 | 73 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // ... 255 | 73 | | -]; | | 74 | +]); | 74 | 75 | // A safe fast alternative to decodeURIComponent | 75 | 76 | function unescapeBuffer(s, decodeSpaces) { | 76 | 77 | const out = Buffer.allocUnsafe(s.length); | @@ -130,7 +131,7 @@ function qsUnescape(s, decodeSpaces) { | 130 | 131 | // digits | 131 | 132 | // alpha (uppercase) | 132 | 133 | // alpha (lowercase) | 133 | | -const noEscape = [ | | 134 | +const noEscape = new Int8Array([ | 134 | 135 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15 | 135 | 136 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31 | 136 | 137 | 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 32 - 47 | @@ -139,7 +140,7 @@ const noEscape = [ | 139 | 140 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 80 - 95 | 140 | 141 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111 | 141 | 142 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 112 - 127 | 142 | | -]; | | 143 | +]); | 143 | 144 | // QueryString.escape() replaces encodeURIComponent() | 144 | 145 | // https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | 145 | 146 | function qsEscape(str) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/url.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | 24 | const { | | 25 | + Int8Array, | 25 | 26 | ObjectCreate, | 26 | 27 | ObjectKeys, | 27 | 28 | SafeSet, | @@ -561,7 +562,7 @@ function urlFormat(urlObject, options) { | 561 | 562 | // digits | 562 | 563 | // alpha (uppercase) | 563 | 564 | // alpha (lowercase) | 564 | | -const noEscapeAuth = [ | | 565 | +const noEscapeAuth = new Int8Array([ | 565 | 566 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00 - 0x0F | 566 | 567 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10 - 0x1F | 567 | 568 | 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 0x20 - 0x2F | @@ -570,7 +571,7 @@ const noEscapeAuth = [ | 570 | 571 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F | 571 | 572 | 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F | 572 | 573 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 0x70 - 0x7F | 573 | | -]; | | 574 | +]); | 574 | 575 |
| 575 | 576 | Url.prototype.format = function format() { | 576 | 577 | let auth = this.auth || ''; | |
|