From 30b306ced6e9a45c70fe5848d86da9734b92a99e 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':