I became suspicious of the Math calls thanks to this thread:
https://groups.google.com/forum/#!msg/google-chrome-developer-tools/Y0J2XQ9iiqU/H60qqZNlQa8J
Turns out, those were the culprit.
): Array<number> {
let result = [];
let carry = 0;
): Array<number> {
let result = [];
let carry = 0;
- for (
- let i = 0, max = Math.max(aDigits.length, bDigits.length);
- i < max || carry;
- i++
- ) {
- const aDigit = aDigits[i] || 0;
- const bDigit = bDigits[i] || 0;
+ for (let i = 0; i < aDigits.length || i < bDigits.length || carry; i++) {
+ const aDigit = i < aDigits.length ? aDigits[i] : 0;
+ const bDigit = i < bDigits.length ? bDigits[i] : 0;
const sum = aDigit + bDigit + carry;
result.push(sum % base);
const sum = aDigit + bDigit + carry;
result.push(sum % base);
- carry = Math.floor(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 : [0];
}