From b34f6763d850d347224b19662841021a62b26b90 Mon Sep 17 00:00:00 2001 From: zhenweijin Date: Tue, 14 Nov 2023 13:35:04 +0800 Subject: [PATCH] util: improve performance of normalizeEncoding --- lib/internal/util.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 4149840b244adc..80ce774a211644 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -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: