From a74fb1e7e8a7a685875ac6f5d5b87e3f03e572a8 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 31 Mar 2015 07:09:20 +0200 Subject: [PATCH] Avoid setting up unnecessary stack frames for function calls --- lib/config/vmops.hpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index a0f3845bd..63acdb35c 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -88,12 +88,7 @@ public: static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const Function::Ptr& func, const std::vector& arguments) { - boost::shared_ptr vframe; - - if (!self.IsEmpty()) - vframe = boost::make_shared(self); /* passes self to the callee using a TLS variable */ - else - vframe = boost::make_shared(); + 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::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 *closedVars)