From ab5b529dd2acf1a6183ab6bd859d4b2992fcd1b6 Mon Sep 17 00:00:00 2001 From: Tom Gallacher Date: Tue, 24 Nov 2015 21:48:03 +0000 Subject: [PATCH] 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 Reviewed-By: Trevor Norris --- lib/buffer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/buffer.js b/lib/buffer.js index 210fdf4f058ff2..dff740e1b2b363 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -272,6 +272,7 @@ function byteLength(string, encoding) { case 'utf8': case 'utf-8': + case undefined: return binding.byteLengthUtf8(string); case 'ucs2':