diff options
author | Brian White <mscdex@mscdex.net> | 2020-05-31 08:18:59 +0300 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2020-06-13 01:21:44 +0300 |
commit | 7b46793eeedd24e576fa1aa7982b436e5cd37edd (patch) | |
tree | 71fc5157fd92ed993d905adcf7e0cd00b8e2527b /lib/internal/querystring.js | |
parent | 76ceaff270a76e9e39e23680a00fe5155c51b57f (diff) |
querystring: improve stringify() performance
PR-URL: https://github.com/nodejs/node/pull/33669
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/internal/querystring.js')
-rw-r--r-- | lib/internal/querystring.js | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/internal/querystring.js b/lib/internal/querystring.js index 7df1c495c6e..ee589e19842 100644 --- a/lib/internal/querystring.js +++ b/lib/internal/querystring.js @@ -36,19 +36,25 @@ function encodeStr(str, noEscapeTable, hexTable) { let out = ''; let lastPos = 0; + let i = 0; - for (let i = 0; i < len; i++) { + outer: + for (; i < len; i++) { let c = str.charCodeAt(i); // ASCII - if (c < 0x80) { - if (noEscapeTable[c] === 1) - continue; - if (lastPos < i) - out += str.slice(lastPos, i); - lastPos = i + 1; - out += hexTable[c]; - continue; + while (c < 0x80) { + if (noEscapeTable[c] !== 1) { + if (lastPos < i) + out += str.slice(lastPos, i); + lastPos = i + 1; + out += hexTable[c]; + } + + if (++i === len) + break outer; + + c = str.charCodeAt(i); } if (lastPos < i) |