From 7c00ec2694be9958fde6711bdda3378e9e203366 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/buffer.js b/lib/buffer.js index f125806622d49d..8f4e34d289fc27 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -276,6 +276,9 @@ function byteLength(string, encoding) { if (typeof(string) !== 'string') string = String(string); + if (string.length === 0) + return 0; + switch (encoding) { case 'ascii': case 'binary':