summaryrefslogtreecommitdiff
path: root/lib/string_decoder.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-02-14 23:48:35 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-03-02 02:09:25 +0000
commit341770fedf77ff5b8e0c646070029152b58fc746 (patch)
tree3b44a68a906b482d100d439c92166a733c9f8254 /lib/string_decoder.js
parent876836b13526fbfc638178f119773aee27c744af (diff)
downloadandroid-node-v8-341770fedf77ff5b8e0c646070029152b58fc746.tar.gz
android-node-v8-341770fedf77ff5b8e0c646070029152b58fc746.tar.bz2
android-node-v8-341770fedf77ff5b8e0c646070029152b58fc746.zip
lib: improve normalize encoding performance
This focuses on the common case by making sure they are prioritized. It also changes some typeof checks to test for undefined since that is faster and it adds a benchmark. PR-URL: https://github.com/nodejs/node/pull/18790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/string_decoder.js')
-rw-r--r--lib/string_decoder.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/string_decoder.js b/lib/string_decoder.js
index 04d31b2607..18097be0e6 100644
--- a/lib/string_decoder.js
+++ b/lib/string_decoder.js
@@ -43,10 +43,12 @@ const kNativeDecoder = Symbol('kNativeDecoder');
// modules monkey-patch it to support additional encodings
function normalizeEncoding(enc) {
const nenc = internalUtil.normalizeEncoding(enc);
- if (typeof nenc !== 'string' &&
- (Buffer.isEncoding === isEncoding || !Buffer.isEncoding(enc)))
- throw new errors.TypeError('ERR_UNKNOWN_ENCODING', enc);
- return nenc || enc;
+ if (nenc === undefined) {
+ if (Buffer.isEncoding === isEncoding || !Buffer.isEncoding(enc))
+ throw new errors.TypeError('ERR_UNKNOWN_ENCODING', enc);
+ return enc;
+ }
+ return nenc;
}
const encodingsMap = {};