From a320045e680855d29fc3054a17e661ae74380e47 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 f6f28294e3c3c7..3d5e96e52f3042 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -276,6 +276,7 @@ function byteLength(string, encoding) { case 'utf8': case 'utf-8': + case undefined: return binding.byteLengthUtf8(string); case 'ucs2':