Skip to content

Commit 7c00ec2

Browse files
committed
buffer: improve Buffer.byteLength(string, encoding)
When string is empty, it will running into binding also. It make the performance is wasted.
1 parent 10e31ba commit 7c00ec2

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

lib/buffer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ function byteLength(string, encoding) {
276276
if (typeof(string) !== 'string')
277277
string = String(string);
278278

279+
if (string.length === 0)
280+
return 0;
281+
279282
switch (encoding) {
280283
case 'ascii':
281284
case 'binary':

0 commit comments

Comments
 (0)