projects
/
platform
/
upstream
/
nodejs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
62f5f4c
)
buffer: fast-case for empty string in byteLength
author
Jackson Tian
<puling.tyq@alibaba-inc.com>
Thu, 16 Apr 2015 15:31:34 +0000
(23:31 +0800)
committer
Jeremiah Senkpiel
<fishrock123@rocketmail.com>
Thu, 16 Apr 2015 22:26:48 +0000
(18:26 -0400)
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>
lib/buffer.js
patch
|
blob
|
history
diff --git
a/lib/buffer.js
b/lib/buffer.js
index
f125806
..
8f4e34d
100644
(file)
--- 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':