Skip to content

Commit

Permalink
util: improve performance of normalizeEncoding
Browse files Browse the repository at this point in the history
PR-URL: #50721
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
  • Loading branch information
kylo5aby authored and UlisesGascon committed Dec 19, 2023
1 parent 68e7d49 commit e6e7f39
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/internal/util.js
Expand Up @@ -219,13 +219,13 @@ function slowCases(enc) {
case 4:
if (enc === 'UTF8') return 'utf8';
if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le';
enc = `${enc}`.toLowerCase();
enc = StringPrototypeToLowerCase(enc);
if (enc === 'utf8') return 'utf8';
if (enc === 'ucs2') return 'utf16le';
break;
case 3:
if (enc === 'hex' || enc === 'HEX' ||
`${enc}`.toLowerCase() === 'hex')
StringPrototypeToLowerCase(enc) === 'hex')
return 'hex';
break;
case 5:
Expand All @@ -234,7 +234,7 @@ function slowCases(enc) {
if (enc === 'UTF-8') return 'utf8';
if (enc === 'ASCII') return 'ascii';
if (enc === 'UCS-2') return 'utf16le';
enc = `${enc}`.toLowerCase();
enc = StringPrototypeToLowerCase(enc);
if (enc === 'utf-8') return 'utf8';
if (enc === 'ascii') return 'ascii';
if (enc === 'ucs-2') return 'utf16le';
Expand All @@ -244,23 +244,23 @@ function slowCases(enc) {
if (enc === 'latin1' || enc === 'binary') return 'latin1';
if (enc === 'BASE64') return 'base64';
if (enc === 'LATIN1' || enc === 'BINARY') return 'latin1';
enc = `${enc}`.toLowerCase();
enc = StringPrototypeToLowerCase(enc);
if (enc === 'base64') return 'base64';
if (enc === 'latin1' || enc === 'binary') return 'latin1';
break;
case 7:
if (enc === 'utf16le' || enc === 'UTF16LE' ||
`${enc}`.toLowerCase() === 'utf16le')
StringPrototypeToLowerCase(enc) === 'utf16le')
return 'utf16le';
break;
case 8:
if (enc === 'utf-16le' || enc === 'UTF-16LE' ||
`${enc}`.toLowerCase() === 'utf-16le')
StringPrototypeToLowerCase(enc) === 'utf-16le')
return 'utf16le';
break;
case 9:
if (enc === 'base64url' || enc === 'BASE64URL' ||
`${enc}`.toLowerCase() === 'base64url')
StringPrototypeToLowerCase(enc) === 'base64url')
return 'base64url';
break;
default:
Expand Down

0 comments on commit e6e7f39

Please sign in to comment.