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 Myles Borins committed Dec 29, 2015
1 parent 4290823 commit 30b306c
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 30b306c

Please sign in to comment.