Skip to content

Commit 9114a30

Browse files
committed
lib: use cached str.length on charCodes
Signed-off-by: RafaelGSS <[email protected]>
1 parent 3e31bae commit 9114a30

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/querystring.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,11 @@ function stringify(obj, sep, eq, options) {
273273
* @returns {number[]}
274274
*/
275275
function charCodes(str) {
276-
if (str.length === 0) return [];
277-
if (str.length === 1) return [StringPrototypeCharCodeAt(str, 0)];
278-
const ret = new Array(str.length);
279-
for (let i = 0; i < str.length; ++i)
276+
const len = str.length;
277+
if (len === 0) return [];
278+
if (len === 1) return [StringPrototypeCharCodeAt(str, 0)];
279+
const ret = new Array(len);
280+
for (let i = 0; i < len; ++i)
280281
ret[i] = StringPrototypeCharCodeAt(str, i);
281282
return ret;
282283
}

0 commit comments

Comments
 (0)