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>
This commit is contained in:
parent
62f5f4cec9
commit
431673ebd1
@ -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':
|
||||
|
Loading…
x
Reference in New Issue
Block a user