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>
This commit is contained in:
Tom Gallacher 2015-11-24 21:48:03 +00:00 committed by cjihrig
parent a881b53954
commit 93739f48ff

View File

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