From 431673ebd1aaa30424921a7ef2fcb18c81b146eb Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Thu, 16 Apr 2015 23:31:34 +0800 Subject: [PATCH] buffer: fast-case for empty string in byteLength When the string is empty, calling the binding is unnecessary and slow. PR-URL: https://github.com/iojs/io.js/pull/1441 Reviewed-by: Jeremiah Senkpiel Reviewed-By: Colin Ihrig Reviewed-By: Christian Tellnes --- 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':