]> zoso.dev Git - buffer.git/commitdiff
Prevent unneeded slice() when calling toString('base64')
authorFeross Aboukhadijeh <feross@feross.org>
Sat, 28 Dec 2013 05:59:24 +0000 (21:59 -0800)
committerFeross Aboukhadijeh <feross@feross.org>
Sat, 28 Dec 2013 05:59:24 +0000 (21:59 -0800)
index.js

index ce7e8540e1bd719cf10c74dbcc2afb7b007add51..cd81b82ced9e0f1828ada04dda841ff8d7e2e190 100644 (file)
--- a/index.js
+++ b/index.js
@@ -359,8 +359,11 @@ function BufferCopy (target, target_start, start, end) {
 }
 
 function _base64Slice (buf, start, end) {
-  var bytes = buf.slice(start, end)
-  return base64.fromByteArray(bytes)
+  if (start === 0 && end === buf.length) {
+    return base64.fromByteArray(buf)
+  } else {
+    return base64.fromByteArray(buf.slice(start, end))
+  }
 }
 
 function _utf8Slice (buf, start, end) {