Skip to content

Commit

Permalink
buffer: fast-case for empty string in byteLength
Browse files Browse the repository at this point in the history
When the string is empty, calling the binding is unnecessary and slow.

PR-URL: #1441
Reviewed-by: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Christian Tellnes <[email protected]>
  • Loading branch information
JacksonTian authored and Fishrock123 committed Apr 16, 2015
1 parent 62f5f4c commit 431673e
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

2 comments on commit 431673e

@Fishrock123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvagg changelog-maker is ok with Reviewed-by right? Dx

@rvagg
Copy link
Member

@rvagg rvagg commented on 431673e Apr 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's an i regex match, but it's not actually used in the changelog anyway so whatever

Please sign in to comment.