mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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>
This commit is contained in:
parent
e5200392a2
commit
cff14bcaef
2 changed files with 8 additions and 11 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue