trying to reduce allocation to shave off a second from iron puzzle

This commit is contained in:
Danny Yoo 2012-01-19 15:23:06 -05:00
parent a23e117b6d
commit 9ed5898c1f
9 changed files with 42 additions and 33 deletions

View File

@ -4,7 +4,7 @@
var colorNamespace = MACHINE.modules['whalesong/image/private/color.rkt'].namespace;
var colorStruct = colorNamespace['struct:color'];
var makeColor = colorStruct.constructor;
var makeColor = function(r,g,b,a) { return colorStruct.constructor([r,g,b,a]); };

View File

@ -6,7 +6,7 @@
//////////////////////////////////////////////////////////////////////
var colorNamespace = MACHINE.modules['whalesong/image/private/color.rkt'].namespace;
var colorStruct = colorNamespace['struct:color'];
var makeColor = colorStruct.constructor;
var makeColor = function(r,g,b,a) { return colorStruct.constructor([r,g,b,a]); };
var isColor = colorStruct.predicate;
var colorRed = function(c) { return colorStruct.accessor(c, 0); };
var colorGreen = function(c) { return colorStruct.accessor(c, 1); };

View File

@ -57,7 +57,10 @@
//////////////////////////////////////////////////////////////////////
exports.ArityAtLeast = ArityAtLeast;
exports.makeArityAtLeast = ArityAtLeast.constructor;
exports.makeArityAtLeast = function() {
var args = [].slice.call(arguments);
return ArityAtLeast.constructor(args);
};
exports.isArityAtLeast = isArityAtLeast;
exports.isArityMatching = isArityMatching;
exports.arityAtLeastValue = arityAtLeastValue;

View File

@ -120,10 +120,10 @@
baselib.exceptions.raise(
MACHINE,
baselib.exceptions.ExnFailContractArity.constructor(
callerName + ": expected at least " + minimum
+ " arguments "
+ " but received " + observed,
MACHINE.captureContinuationMarks()));
[callerName + ": expected at least " + minimum
+ " arguments "
+ " but received " + observed,
MACHINE.captureContinuationMarks()]));
}
};

View File

@ -81,12 +81,12 @@
var raiseFailure = function(MACHINE, msg) {
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE, ExnFail.constructor(msg, contMarks));
raise(MACHINE, ExnFail.constructor([msg, contMarks]));
};
var raiseContractError = function(MACHINE, msg) {
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE, ExnFailContract.constructor(msg, contMarks));
raise(MACHINE, ExnFailContract.constructor([msg, contMarks]));
};
@ -95,9 +95,9 @@
var message = baselib.format.format("Not bound: ~a", [name]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
ExnFailContractVariable.constructor(message,
contMarks,
baselib.symbols.makeSymbol(name)));
ExnFailContractVariable.constructor([message,
contMarks,
baselib.symbols.makeSymbol(name)]));
};
@ -115,14 +115,14 @@
expectedTypeName,
(argumentOffset + 1),
actualValue]);
raise(MACHINE, ExnFailContract.constructor(message, contMarks));
raise(MACHINE, ExnFailContract.constructor([message, contMarks]));
} else {
message = baselib.format.format(
"~a: expected ~a but received ~e",
[callerName,
expectedTypeName,
actualValue]);
raise(MACHINE, ExnFailContract.constructor(message, contMarks));
raise(MACHINE, ExnFailContract.constructor([message, contMarks]));
}
};
@ -130,7 +130,7 @@
var message = baselib.format.format("expected ~e values, received ~e values",
[expected, MACHINE.a]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE, ExnFailContract.constructor(message, contMarks));
raise(MACHINE, ExnFailContract.constructor([message, contMarks]));
};
var raiseArityMismatchError = function(MACHINE, proc, received) {
@ -139,7 +139,7 @@
proc.racketArity,
received]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE, ExnFailContractArity.constructor(message, contMarks));
raise(MACHINE, ExnFailContractArity.constructor([message, contMarks]));
};
var raiseOperatorApplicationError = function(MACHINE, operator) {
@ -147,7 +147,7 @@
[operator]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
ExnFailContract.constructor(message, contMarks));
ExnFailContract.constructor([message, contMarks]));
};
@ -156,7 +156,7 @@
[operator]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
ExnFailContract.constructor(message, contMarks));
ExnFailContract.constructor([message, contMarks]));
};
@ -164,7 +164,7 @@
var message = "unimplemented kernel procedure: " + name;
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
ExnFailContract.constructor(message, contMarks));
ExnFailContract.constructor([message, contMarks]));
};
@ -184,32 +184,32 @@
exceptions.isRacketError = isRacketError;
exceptions.Exn = Exn;
exceptions.makeExn = Exn.constructor;
exceptions.makeExn = function(msg, marks) { return Exn.constructor([msg, marks]); };
exceptions.isExn = Exn.predicate;
exceptions.exnMessage = function(exn) { return Exn.accessor(exn, 0); };
exceptions.exnContMarks = function(exn) { return Exn.accessor(exn, 1); };
exceptions.exnSetContMarks = function(exn, v) { Exn.mutator(exn, 1, v); };
exceptions.ExnBreak = ExnBreak;
exceptions.makeExnBreak = ExnBreak.constructor;
exceptions.makeExnBreak = function(msg, marks) { return ExnBreak.constructor([msg, marks]); };
exceptions.isExnBreak = ExnBreak.predicate;
exceptions.exnBreakContinuation =
function(exn) { return ExnBreak.accessor(exn, 0); };
exceptions.ExnFail = ExnFail;
exceptions.makeExnFail = ExnFail.constructor;
exceptions.makeExnFail = function(msg, marks) { return ExnFail.constructor([msg, marks]); };
exceptions.isExnFail = ExnFail.predicate;
exceptions.ExnFailContract = ExnFailContract;
exceptions.makeExnFailContract = ExnFailContract.constructor;
exceptions.makeExnFailContract = function(msg, marks) { return ExnFailContract.constructor([msg, marks]); };
exceptions.isExnFailContract = ExnFailContract.predicate;
exceptions.ExnFailContractArity = ExnFailContractArity;
exceptions.makeExnFailContractArity = ExnFailContractArity.constructor;
exceptions.makeExnFailContractArity = function(msg, marks) { return ExnFailContractArity.constructor([msg, marks]); };
exceptions.isExnFailContractArity = ExnFailContractArity.predicate;
exceptions.ExnFailContractVariable = ExnFailContractVariable;
exceptions.makeExnFailContractVariable = ExnFailContractVariable.constructor;
exceptions.makeExnFailContractVariable = function(msg, marks) { return ExnFailContractVariable.constructor([msg, marks]); };
exceptions.isExnFailContractVariable = ExnFailContractVariable.predicate;
exceptions.exnFailContractVariableId =
function(exn) { return ExnFailContractVariable.accessor(exn, 0); };
@ -217,7 +217,7 @@
exceptions.ExnFailContractDivisionByZero = ExnFailContractDivisionByZero;
exceptions.makeExnFailContractDivisionByZero =
ExnFailContractDivisionByZero.constructor;
function(msg, marks) { return ExnFailContractDivisionByZero.constructor([msg, marks]); };
exceptions.isExnFailContractDivisionByZero = ExnFailContractDivisionByZero.predicate;

View File

@ -2250,7 +2250,7 @@
initFieldCount + (superType ? superType.numberOfArgs : 0),
function (M) {
var args = M.e.slice(M.e.length - M.a).reverse();
return structType.constructor.apply(null, args);
return structType.constructor(args);
});
var predicateValue =

View File

@ -9,7 +9,10 @@
var srcloc = baselib.structs.makeStructureType(
'srcloc', false, 5, 0, false, false);
var makeSrcloc = srcloc.constructor;
var makeSrcloc = function() {
var args = [].slice.call(arguments);
return srcloc.constructor(args);
};
var isSrcloc = srcloc.predicate;
var srclocSource = function(x) { return srcloc.accessor(x, 0); };

View File

@ -184,6 +184,11 @@
// Set type, necessary for equality checking
RawConstructor.prototype.type = RawConstructor;
var constructAfterGuard = function (res) {
return new RawConstructor(theName, res, newType);
};
// The structure type consists of the name, its constructor, a
// record of how many argument it and its parent type contains,
// the list of autofields, the guard, and functions corresponding
@ -206,13 +211,11 @@
});
},
// constructor
function () {
var args = [].slice.call(arguments);
function (args) {
return newType.applyGuard(
args,
baselib.symbols.Symbol.makeInstance(theName),
function (res) {
return new RawConstructor(theName, res, newType); });
constructAfterGuard);
},
// predicate

View File

@ -891,7 +891,7 @@
}
}
}
return eventStructType.constructor(result);
return eventStructType.constructor([result]);
};