Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5a2d2da

Browse filesBrowse files
joyeecheungmarco-ippolito
authored andcommitted
lib: move encodingsMap to internal/util
PR-URL: #51044 Refs: nodejs/performance#136 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
1 parent 4ebb944 commit 5a2d2da
Copy full SHA for 5a2d2da

File tree

Expand file treeCollapse file tree

3 files changed

+14
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-13
lines changed
Open diff view settings
Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const {
8585
normalizeEncoding,
8686
kIsEncodingSymbol,
8787
defineLazyProperties,
88+
encodingsMap,
8889
} = require('internal/util');
8990
const {
9091
isAnyArrayBuffer,
@@ -95,7 +96,6 @@ const {
9596
const {
9697
inspect: utilInspect,
9798
} = require('internal/util/inspect');
98-
const { encodings } = internalBinding('string_decoder');
9999

100100
const {
101101
codes: {
@@ -149,10 +149,6 @@ const constants = ObjectDefineProperties({}, {
149149
Buffer.poolSize = 8 * 1024;
150150
let poolSize, poolOffset, allocPool;
151151

152-
const encodingsMap = { __proto__: null };
153-
for (let i = 0; i < encodings.length; ++i)
154-
encodingsMap[encodings[i]] = i;
155-
156152
function createPool() {
157153
poolSize = Buffer.poolSize;
158154
allocPool = createUnsafeBuffer(poolSize).buffer;
Collapse file

‎lib/internal/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/util.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const {
6565
} = internalBinding('util');
6666
const { isNativeError, isPromise } = internalBinding('types');
6767
const { getOptionValue } = require('internal/options');
68+
const { encodings } = internalBinding('string_decoder');
6869

6970
const noCrypto = !process.versions.openssl;
7071

@@ -859,6 +860,10 @@ class WeakReference {
859860
}
860861
}
861862

863+
const encodingsMap = { __proto__: null };
864+
for (let i = 0; i < encodings.length; ++i)
865+
encodingsMap[encodings[i]] = i;
866+
862867
module.exports = {
863868
getLazy,
864869
assertCrypto,
@@ -872,6 +877,7 @@ module.exports = {
872877
defineReplaceableLazyAttribute,
873878
deprecate,
874879
emitExperimentalWarning,
880+
encodingsMap,
875881
exposeInterface,
876882
exposeLazyInterfaces,
877883
exposeNamespace,
Collapse file

‎lib/string_decoder.js‎

Copy file name to clipboardExpand all lines: lib/string_decoder.js
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@ const {
3838
kSize,
3939
decode,
4040
flush,
41-
encodings,
4241
} = internalBinding('string_decoder');
43-
const internalUtil = require('internal/util');
42+
const {
43+
kIsEncodingSymbol,
44+
encodingsMap,
45+
normalizeEncoding: _normalizeEncoding,
46+
} = require('internal/util');
4447
const {
4548
ERR_INVALID_ARG_TYPE,
4649
ERR_INVALID_THIS,
4750
ERR_UNKNOWN_ENCODING,
4851
} = require('internal/errors').codes;
49-
const isEncoding = Buffer[internalUtil.kIsEncodingSymbol];
52+
const isEncoding = Buffer[kIsEncodingSymbol];
5053

5154
const kNativeDecoder = Symbol('kNativeDecoder');
5255

@@ -60,7 +63,7 @@ const kNativeDecoder = Symbol('kNativeDecoder');
6063
* @throws {TypeError} Throws an error when encoding is invalid
6164
*/
6265
function normalizeEncoding(enc) {
63-
const nenc = internalUtil.normalizeEncoding(enc);
66+
const nenc = _normalizeEncoding(enc);
6467
if (nenc === undefined) {
6568
if (Buffer.isEncoding === isEncoding || !Buffer.isEncoding(enc))
6669
throw new ERR_UNKNOWN_ENCODING(enc);
@@ -69,10 +72,6 @@ function normalizeEncoding(enc) {
6972
return nenc;
7073
}
7174

72-
const encodingsMap = {};
73-
for (let i = 0; i < encodings.length; ++i)
74-
encodingsMap[encodings[i]] = i;
75-
7675
/**
7776
* StringDecoder provides an interface for efficiently splitting a series of
7877
* buffers into a series of JS strings without breaking apart multi-byte

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.