Skip to content

Commit 431673e

Browse files
JacksonTianFishrock123
authored andcommitted
buffer: fast-case for empty string in byteLength
When the string is empty, calling the binding is unnecessary and slow. PR-URL: #1441 Reviewed-by: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Christian Tellnes <[email protected]>
1 parent 62f5f4c commit 431673e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/buffer.js

+3
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ function byteLength(string, encoding) {
276276
if (typeof(string) !== 'string')
277277
string = String(string);
278278

279+
if (string.length === 0)
280+
return 0;
281+
279282
switch (encoding) {
280283
case 'ascii':
281284
case 'binary':

0 commit comments

Comments
 (0)