From c5c33c5e89358b9f84358d5b574835fe6517f483 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Thu, 16 Apr 2015 23:31:34 +0800 Subject: [PATCH] buffer: improve Buffer.byteLength(string, encoding) When string is empty, it will running into binding also. It make the performance is wasted. --- lib/buffer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/buffer.js b/lib/buffer.js index f125806622d49d..b391697fe751e7 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -276,6 +276,10 @@ function byteLength(string, encoding) { if (typeof(string) !== 'string') string = String(string); + if (string.length === 0) { + return 0; + } + switch (encoding) { case 'ascii': case 'binary':