Skip to content

Commit 4a28077

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 4a28077

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/buffer.js

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

279+
if (string.length === 0) return 0;
280+
279281
switch (encoding) {
280282
case 'ascii':
281283
case 'binary':

0 commit comments

Comments
 (0)