low-hanging fruit optimizations

This commit is contained in:
Danny Yoo 2012-02-21 13:23:30 -05:00
parent 3d34c22b97
commit 06bc6ad34e
3 changed files with 47 additions and 4 deletions

View File

@ -81,7 +81,10 @@
(format "RT.checkedNumEqualsSlowPath(M, [~a])" (string-join operands ","))])]
[(>)
(assemble-boolean-chain "plt.baselib.numbers.greaterThan" checked-operands)]
(format "RT.checkedGreaterThan(M, ~a)"
(string-join operands ","))
;; (assemble-boolean-chain "plt.baselib.numbers.greaterThan" checked-operands)
]
[(>=)
(assemble-boolean-chain "plt.baselib.numbers.greaterThanOrEqual" checked-operands)]

View File

@ -833,9 +833,22 @@
testArgument(M, 'number', isNumber, n, 0, '-'));
};
var checkedAdd = function(M) {
var checkedAdd = function(M, x, y) {
var i;
var sum = 0;
var sum;
// fast path optimization: binop addition on fixnums
if (arguments.length === 3) {
if (typeof(x) === 'number' &&
typeof(y) === 'number') {
sum = x + y;
if (sum < -9e15 || sum > 9e15) {
return checkedAddSlowPath(M, Array.prototype.slice.call(arguments, 1));
}
return sum;
}
}
sum = 0;
for (i = 1; i < arguments.length; i++) {
if (typeof(arguments[i]) === 'number') {
sum += arguments[i];
@ -896,6 +909,32 @@
return sum;
};
var checkedGreaterThan = function(M, x, y) {
var i;
// fast path optimization: binop comparison on fixnums
if (arguments.length === 3) {
if (typeof(x) === 'number' && typeof(y) === 'number') {
return x > y;
}
}
// Slow path.
if (! isNumber(arguments[1])) {
raiseArgumentTypeError(M, '>', 'number', 0, arguments[1]);
}
for (i = 2; i < arguments.length ; i++) {
if (! isNumber(arguments[i])) {
raiseArgumentTypeError(M, '>', 'number', i-1, arguments[i]);
}
if (! plt.baselib.numbers.greaterThan(arguments[i-1],
arugments[i])) {
return false;
}
}
return true;
};
var checkedNumEquals = function(M) {
// Assumption: at least two arguments to compare
var i;
@ -1086,6 +1125,7 @@
exports['checkedSubSlowPath'] = checkedSubSlowPath;
exports['checkedNumEquals'] = checkedNumEquals;
exports['checkedNumEqualsSlowPath'] = checkedNumEqualsSlowPath;
exports['checkedGreaterThan'] = checkedGreaterThan;
exports['checkedCar'] = checkedCar;
exports['checkedCdr'] = checkedCdr;
}(this.plt, this.plt.baselib));

View File

@ -7,4 +7,4 @@
(provide version)
(: version String)
(define version "1.156")
(define version "1.157")