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: nodejs#4010
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information
tomgco authored and Michael Scovetta committed Apr 2, 2016
1 parent 582802f commit 38cb40e
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 38cb40e

Please sign in to comment.