From 185f77ddddf6162a9568ca7e7d1d21ee212d3ad5 Mon Sep 17 00:00:00 2001 From: kylo5aby <109658203+zhenweijin@users.noreply.github.com> Date: Fri, 17 Nov 2023 04:53:38 +0800 Subject: [PATCH] util: improve performance of normalizeEncoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/50721 Reviewed-By: Marco Ippolito Reviewed-By: Vinícius Lourenço Claro Cardoso --- 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: