Skip to content

Commit

Permalink
buffer: default to UTF8 in byteLength()
Browse files Browse the repository at this point in the history
If an undefined encoding is passed to byteLength(),
assume that it is UTF8 immediately. This yields a
small speedup, as it prevents string operations on
the encoding argument.

PR-URL: #4010
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information
tomgco authored and Myles Borins committed Jan 19, 2016
1 parent bb158f8 commit a320045
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ function byteLength(string, encoding) {

case 'utf8':
case 'utf-8':
case undefined:
return binding.byteLengthUtf8(string);

case 'ucs2':
Expand Down

0 comments on commit a320045

Please sign in to comment.