summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJackson Tian <puling.tyq@alibaba-inc.com>2015-04-16 23:31:34 +0800
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2015-04-16 18:26:48 -0400
commit431673ebd1aaa30424921a7ef2fcb18c81b146eb (patch)
treebfba4b1afe1757fae20b3435483264958f1029b9 /lib
parent62f5f4cec942864d1cd21ef31bf650ddca874093 (diff)
downloadnode-new-431673ebd1aaa30424921a7ef2fcb18c81b146eb.tar.gz
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 <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Christian Tellnes <christian@tellnes.no>
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.js3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index f125806622..8f4e34d289 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':