Avoid setting up unnecessary stack frames for function calls

This commit is contained in:
Gunnar Beutner 2015-03-31 07:09:20 +02:00
parent 8f1ba7f84c
commit a74fb1e7e8
1 changed files with 5 additions and 11 deletions

View File

@ -88,12 +88,7 @@ public:
static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const Function::Ptr& func, const std::vector<Value>& arguments)
{
boost::shared_ptr<ScriptFrame> vframe;
if (!self.IsEmpty())
vframe = boost::make_shared<ScriptFrame>(self); /* passes self to the callee using a TLS variable */
else
vframe = boost::make_shared<ScriptFrame>();
ScriptFrame vframe = (self.IsEmpty()) ? ScriptFrame() : ScriptFrame(self);
return func->Invoke(arguments);
}
@ -334,16 +329,15 @@ private:
if (arguments.size() < funcargs.size())
BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function"));
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
ScriptFrame frame(vframe->Self);
ScriptFrame *frame = ScriptFrame::GetCurrentFrame();
if (closedVars)
closedVars->CopyTo(frame.Locals);
closedVars->CopyTo(frame->Locals);
for (std::vector<Value>::size_type i = 0; i < std::min(arguments.size(), funcargs.size()); i++)
frame.Locals->Set(funcargs[i], arguments[i]);
frame->Locals->Set(funcargs[i], arguments[i]);
return expr->Evaluate(frame);
return expr->Evaluate(*frame);
}
static inline Dictionary::Ptr EvaluateClosedVars(ScriptFrame& frame, std::map<String, Expression *> *closedVars)