nested: Use early exit instead of giant if in DtoCreateNestedContextType [nfc]

This commit is contained in:
David Nadlinger 2016-02-06 21:16:05 +01:00
parent 03429eb60f
commit 0c7660a98b

View file

@ -328,6 +328,7 @@ static void DtoCreateNestedContextType(FuncDeclaration *fd) {
IrFunction &irFunc = *getIrFunc(fd); IrFunction &irFunc = *getIrFunc(fd);
if (irFunc.nestedContextCreated) { if (irFunc.nestedContextCreated) {
Logger::println("already done");
return; return;
} }
irFunc.nestedContextCreated = true; irFunc.nestedContextCreated = true;
@ -338,9 +339,22 @@ static void DtoCreateNestedContextType(FuncDeclaration *fd) {
DtoCreateNestedContextType(parentFunc); DtoCreateNestedContextType(parentFunc);
} }
// construct nested variables array if (fd->closureVars.dim == 0) {
if (fd->closureVars.dim > 0) { // No local variables of this function are captured.
if (parentFunc) {
// Propagate context arg properties if the context arg is passed on
// unmodified.
IrFunction &parentIrFunc = *getIrFunc(parentFunc);
irFunc.frameType = parentIrFunc.frameType;
irFunc.frameTypeAlignment = parentIrFunc.frameTypeAlignment;
irFunc.depth = parentIrFunc.depth;
}
return;
}
Logger::println("has nested frame"); Logger::println("has nested frame");
// construct nested variables array
// start with adding all enclosing parent frames until a static parent is // start with adding all enclosing parent frames until a static parent is
// reached // reached
@ -428,17 +442,6 @@ static void DtoCreateNestedContextType(FuncDeclaration *fd) {
// Store type in IrFunction // Store type in IrFunction
irFunc.frameType = frameType; irFunc.frameType = frameType;
irFunc.frameTypeAlignment = builder.overallAlignment(); irFunc.frameTypeAlignment = builder.overallAlignment();
} else // no captured variables
{
if (parentFunc) {
// Propagate context arg properties if the context arg is passed on
// unmodified.
IrFunction &parentIrFunc = *getIrFunc(parentFunc);
irFunc.frameType = parentIrFunc.frameType;
irFunc.frameTypeAlignment = parentIrFunc.frameTypeAlignment;
irFunc.depth = parentIrFunc.depth;
}
}
} }
void DtoCreateNestedContext(FuncDeclaration *fd) { void DtoCreateNestedContext(FuncDeclaration *fd) {