Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRongjian Zhang <pd4d10@gmail.com>2022-03-29 20:48:37 +0300
committerGitHub <noreply@github.com>2022-03-29 20:48:37 +0300
commitcff14bcaefe5dbde570a06aa751727d6b2b69129 (patch)
tree6060f44c6a283c271a7fd56b03c6edb7a156e04d /lib
parente5200392a258f3a5d087a432ff565313e8a54bd1 (diff)
buffer: refactor `byteLength` to remove outdated optimizations
The third argument `mustMatch` is now outdated, so remove it. Fixes: https://github.com/nodejs/node/issues/38536 PR-URL: https://github.com/nodejs/node/pull/38545 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.js17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index 57d6cddbaa2..8e29ac1822a 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -738,17 +738,16 @@ function byteLength(string, encoding) {
}
const len = string.length;
- const mustMatch = (arguments.length > 2 && arguments[2] === true);
- if (!mustMatch && len === 0)
+ if (len === 0)
return 0;
- if (!encoding)
- return (mustMatch ? -1 : byteLengthUtf8(string));
-
- const ops = getEncodingOps(encoding);
- if (ops === undefined)
- return (mustMatch ? -1 : byteLengthUtf8(string));
- return ops.byteLength(string);
+ if (encoding) {
+ const ops = getEncodingOps(encoding);
+ if (ops) {
+ return ops.byteLength(string);
+ }
+ }
+ return byteLengthUtf8(string);
}
Buffer.byteLength = byteLength;