From b1098ede9306e43ea90814b1ccaee61a0291a26e Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 18 Feb 2016 22:05:16 -0600 Subject: [PATCH] Restore "direct" call optimization for DECORATE --- src/thingdef/thingdef.cpp | 2 +- src/thingdef/thingdef_exp.h | 7 ++++--- src/thingdef/thingdef_expression.cpp | 31 ++++++++++++---------------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index 4cb03111b..7d6fb9769 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -277,7 +277,7 @@ static void FinishThingdef() // Can we call this function directly without wrapping it in an // anonymous function? e.g. Are we passing any parameters to it? - func = NULL;//tcall->Code->GetDirectFunction(); + func = tcall->Code->GetDirectFunction(); if (func == NULL) { FCompileContext ctx(tcall->ActorClass); diff --git a/src/thingdef/thingdef_exp.h b/src/thingdef/thingdef_exp.h index 0ec4c95d7..d78638815 100644 --- a/src/thingdef/thingdef_exp.h +++ b/src/thingdef/thingdef_exp.h @@ -835,9 +835,9 @@ public: FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); ExpEmit Emit(VMFunctionBuilder *build, bool tailcall); - unsigned GetArgCount() { return ArgList == NULL ? 0 : ArgList->Size(); } - VMFunction *GetVMFunction() { return Function->Variants[0].Implementation; } - VMFunction *GetDirectFunction(); + unsigned GetArgCount() const { return ArgList == NULL ? 0 : ArgList->Size(); } + VMFunction *GetVMFunction() const { return Function->Variants[0].Implementation; } + bool IsDirectFunction(); }; //========================================================================== @@ -891,6 +891,7 @@ public: FxReturnStatement(FxVMFunctionCall *call, const FScriptPosition &pos); FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); + VMFunction *GetDirectFunction(); }; //========================================================================== diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index c94d6840d..742f5b52d 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -3202,24 +3202,6 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build, bool tailcall) } } -//========================================================================== -// -// FxVMFunctionCall :: GetDirectFunction -// -// If the function is not passed any explicit arguments, returns the -// function. Otherwise returns NULL. -// -//========================================================================== - -VMFunction *FxVMFunctionCall::GetDirectFunction() -{ - if (GetArgCount() == 0) - { - return GetVMFunction(); - } - return NULL; -} - //========================================================================== // // @@ -3505,6 +3487,19 @@ ExpEmit FxReturnStatement::Emit(VMFunctionBuilder *build) return ExpEmit(); } +VMFunction *FxReturnStatement::GetDirectFunction() +{ + // If this return statement calls a function with no arguments, + // then it can be a "direct" function. That is, the DECORATE + // definition can call that function directly without wrapping + // it inside VM code. + if (Call != NULL && Call->GetArgCount() == 0) + { + return Call->GetVMFunction(); + } + return NULL; +} + //========================================================================== // //==========================================================================