Browse Source

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: https://github.com/nodejs/node/pull/4010
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v5.x
Tom Gallacher 9 years ago
committed by Rod Vagg
parent
commit
ab5b529dd2
  1. 1
      lib/buffer.js

1
lib/buffer.js

@ -272,6 +272,7 @@ function byteLength(string, encoding) {
case 'utf8':
case 'utf-8':
case undefined:
return binding.byteLengthUtf8(string);
case 'ucs2':

Loading…
Cancel
Save