Skip to content

Commit

Permalink
buffer: improve Buffer.byteLength(string, encoding)
Browse files Browse the repository at this point in the history
When string is empty, it will running into binding also.
It make the performance is wasted.
  • Loading branch information
JacksonTian committed Apr 16, 2015
1 parent 10e31ba commit 7c00ec2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ function byteLength(string, encoding) {
if (typeof(string) !== 'string')
string = String(string);

if (string.length === 0)
return 0;

switch (encoding) {
case 'ascii':
case 'binary':
Expand Down

0 comments on commit 7c00ec2

Please sign in to comment.