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 <cjihrig@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
tomgco authored and rvagg committed Dec 5, 2015
1 parent ed255ab commit ab5b529
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 @@ -272,6 +272,7 @@ function byteLength(string, encoding) {

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

case 'ucs2':
Expand Down

0 comments on commit ab5b529

Please sign in to comment.