util: improve performance of normalizeEncoding

PR-URL: https://github.com/nodejs/node/pull/50721
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
kylo5aby 2023-11-17 04:53:38 +08:00 committed by GitHub
parent bfe32ec016
commit daf723affd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -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:
@ -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';
@ -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: