Skip to content

Commit 93739f4

Browse files
tomgcocjihrig
authored andcommitted
buffer: default to UTF8 in byteLength()
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]>
1 parent a881b53 commit 93739f4

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/buffer.js

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ function byteLength(string, encoding) {
272272

273273
case 'utf8':
274274
case 'utf-8':
275+
case undefined:
275276
return binding.byteLengthUtf8(string);
276277

277278
case 'ucs2':

0 commit comments

Comments
 (0)