]> git.wincent.com - hextrapolate.git/commitdiff
Replace `unshift()` with `push()` plus `reverse()`
authorGreg Hurrell <greg@hurrell.net>
Thu, 1 Jun 2017 15:16:38 +0000 (08:16 -0700)
committerGreg Hurrell <greg@hurrell.net>
Thu, 1 Jun 2017 15:16:38 +0000 (08:16 -0700)
As predicted, this is faster. Not sure if as fast as what I had before.
Will do actual profiling and revert to prior state if it ends up being
better.

src/addDigits.js

index 566b463062fdccc9b09fb6f769aa384e4a23fe63..e42f6f6ed3587c1fc23989ca3d4ed0cd772368ac 100644 (file)
@@ -18,11 +18,11 @@ export default function addDigits(
     const aDigit = i < aLength ? aDigits[aLength - i - 1] : 0;
     const bDigit = i < bLength ? bDigits[bLength - i - 1] : 0;
     const sum = aDigit + bDigit + carry;
     const aDigit = i < aLength ? aDigits[aLength - i - 1] : 0;
     const bDigit = i < bLength ? bDigits[bLength - i - 1] : 0;
     const sum = aDigit + bDigit + carry;
-    result.unshift(sum % base);
+    result.push(sum % base);
 
     // ~~ here is the equivalent of Math.floor; used to avoid V8 de-opt,
     // "Reference to a variable which requires dynamic lookup".
     carry = ~~(sum / base);
   }
 
     // ~~ here is the equivalent of Math.floor; used to avoid V8 de-opt,
     // "Reference to a variable which requires dynamic lookup".
     carry = ~~(sum / base);
   }
-  return result.length ? result : [0];
+  return result.length ? result.reverse() : [0];
 }
 }