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 cjihrig committed Nov 25, 2015
1 parent a881b53 commit 93739f4
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 93739f4

Please sign in to comment.