* Optimise null-ary term builders. Also declare all term builder

functions as pure, which might improve performance a bit.
This commit is contained in:
Eelco Dolstra 2006-05-02 21:58:46 +00:00
parent 68174bdc7d
commit d300b4383d
3 changed files with 16 additions and 7 deletions

View File

@ -99,8 +99,17 @@ while (<STDIN>) {
print IMPL "AFun sym$funname = 0;\n"; print IMPL "AFun sym$funname = 0;\n";
if ($arity == 0) {
print HEADER "extern ATerm const$funname;\n\n";
print IMPL "ATerm const$funname = 0;\n";
}
print HEADER "static inline $result make$funname($formals) __attribute__ ((pure, nothrow));\n";
print HEADER "static inline $result make$funname($formals) {\n"; print HEADER "static inline $result make$funname($formals) {\n";
if ($arity <= 6) { if ($arity == 0) {
print HEADER " return const$funname;\n";
}
elsif ($arity <= 6) {
print HEADER " return (ATerm) ATmakeAppl$arity(sym$funname$args);\n"; print HEADER " return (ATerm) ATmakeAppl$arity(sym$funname$args);\n";
} else { } else {
$args =~ s/^,//; $args =~ s/^,//;
@ -119,6 +128,10 @@ while (<STDIN>) {
$init .= " sym$funname = ATmakeAFun(\"$const\", $arity, ATfalse);\n"; $init .= " sym$funname = ATmakeAFun(\"$const\", $arity, ATfalse);\n";
$init .= " ATprotectAFun(sym$funname);\n"; $init .= " ATprotectAFun(sym$funname);\n";
if ($arity == 0) {
$init .= " const$funname = (ATerm) ATmakeAppl0(sym$funname);\n";
$init .= " ATprotect(&const$funname);\n";
}
} }
elsif (/^\s*(\w+)\s*=\s*(.*)$/) { elsif (/^\s*(\w+)\s*=\s*(.*)$/) {

View File

@ -6,8 +6,6 @@
EvalState::EvalState() EvalState::EvalState()
: normalForms(32768, 50) : normalForms(32768, 50)
{ {
blackHole = makeBlackHole();
nrEvaluated = nrCached = 0; nrEvaluated = nrCached = 0;
initNixExprHelpers(); initNixExprHelpers();
@ -490,14 +488,14 @@ Expr evalExpr(EvalState & state, Expr e)
previously evaluated expressions. */ previously evaluated expressions. */
Expr nf = state.normalForms.get(e); Expr nf = state.normalForms.get(e);
if (nf) { if (nf) {
if (nf == state.blackHole) if (nf == makeBlackHole())
throw Error("infinite recursion encountered"); throw Error("infinite recursion encountered");
state.nrCached++; state.nrCached++;
return nf; return nf;
} }
/* Otherwise, evaluate and memoize. */ /* Otherwise, evaluate and memoize. */
state.normalForms.set(e, state.blackHole); state.normalForms.set(e, makeBlackHole());
try { try {
nf = evalExpr2(state, e); nf = evalExpr2(state, e);
} catch (Error & err) { } catch (Error & err) {
@ -536,5 +534,4 @@ void printEvalStats(EvalState & state)
% state.nrEvaluated % state.nrCached % state.nrEvaluated % state.nrCached
% ((float) state.nrCached / (float) state.nrEvaluated * 100) % ((float) state.nrCached / (float) state.nrEvaluated * 100)
% AT_calcAllocatedSize()); % AT_calcAllocatedSize());
sleep(100);
} }

View File

@ -29,7 +29,6 @@ struct EvalState
DrvRoots drvRoots; DrvRoots drvRoots;
DrvHashes drvHashes; /* normalised derivation hashes */ DrvHashes drvHashes; /* normalised derivation hashes */
SrcToStore srcToStore; SrcToStore srcToStore;
Expr blackHole;
unsigned int nrEvaluated; unsigned int nrEvaluated;
unsigned int nrCached; unsigned int nrCached;