Skip to content

Commit

Permalink
util: improve performance of normalizeEncoding
Browse files Browse the repository at this point in the history
PR-URL: nodejs#50721
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
  • Loading branch information
kylo5aby authored and martenrichter committed Nov 26, 2023
1 parent 57d3131 commit 185f77d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,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 @@ -235,7 +235,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 @@ -245,23 +245,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 185f77d

Please sign in to comment.