Skip to content

Commit eaa4c14

Browse files
kylo5abytargos
authored andcommitted
util: improve performance of normalizeEncoding
PR-URL: #50721 Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
1 parent 071e46a commit eaa4c14

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/internal/util.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ function slowCases(enc) {
220220
case 4:
221221
if (enc === 'UTF8') return 'utf8';
222222
if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le';
223-
enc = `${enc}`.toLowerCase();
223+
enc = StringPrototypeToLowerCase(enc);
224224
if (enc === 'utf8') return 'utf8';
225225
if (enc === 'ucs2') return 'utf16le';
226226
break;
227227
case 3:
228228
if (enc === 'hex' || enc === 'HEX' ||
229-
`${enc}`.toLowerCase() === 'hex')
229+
StringPrototypeToLowerCase(enc) === 'hex')
230230
return 'hex';
231231
break;
232232
case 5:
@@ -235,7 +235,7 @@ function slowCases(enc) {
235235
if (enc === 'UTF-8') return 'utf8';
236236
if (enc === 'ASCII') return 'ascii';
237237
if (enc === 'UCS-2') return 'utf16le';
238-
enc = `${enc}`.toLowerCase();
238+
enc = StringPrototypeToLowerCase(enc);
239239
if (enc === 'utf-8') return 'utf8';
240240
if (enc === 'ascii') return 'ascii';
241241
if (enc === 'ucs-2') return 'utf16le';
@@ -245,23 +245,23 @@ function slowCases(enc) {
245245
if (enc === 'latin1' || enc === 'binary') return 'latin1';
246246
if (enc === 'BASE64') return 'base64';
247247
if (enc === 'LATIN1' || enc === 'BINARY') return 'latin1';
248-
enc = `${enc}`.toLowerCase();
248+
enc = StringPrototypeToLowerCase(enc);
249249
if (enc === 'base64') return 'base64';
250250
if (enc === 'latin1' || enc === 'binary') return 'latin1';
251251
break;
252252
case 7:
253253
if (enc === 'utf16le' || enc === 'UTF16LE' ||
254-
`${enc}`.toLowerCase() === 'utf16le')
254+
StringPrototypeToLowerCase(enc) === 'utf16le')
255255
return 'utf16le';
256256
break;
257257
case 8:
258258
if (enc === 'utf-16le' || enc === 'UTF-16LE' ||
259-
`${enc}`.toLowerCase() === 'utf-16le')
259+
StringPrototypeToLowerCase(enc) === 'utf-16le')
260260
return 'utf16le';
261261
break;
262262
case 9:
263263
if (enc === 'base64url' || enc === 'BASE64URL' ||
264-
`${enc}`.toLowerCase() === 'base64url')
264+
StringPrototypeToLowerCase(enc) === 'base64url')
265265
return 'base64url';
266266
break;
267267
default:

0 commit comments

Comments
 (0)