Avoid unnecessary allocations for script frames

This commit is contained in:
Gunnar Beutner 2017-12-18 10:30:20 +01:00
parent 80b72cfb1c
commit 4866f777cc
4 changed files with 10 additions and 9 deletions

View File

@ -38,14 +38,13 @@ Function::Function(const String& name, const Callback& function, const std::vect
Value Function::Invoke(const std::vector<Value>& arguments)
{
ScriptFrame frame;
ScriptFrame frame(false);
return m_Callback(arguments);
}
Value Function::InvokeThis(const Value& otherThis, const std::vector<Value>& arguments)
{
ScriptFrame frame;
frame.Self = otherThis;
ScriptFrame frame(otherThis, false);
return m_Callback(arguments);
}

View File

@ -40,14 +40,14 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
ScriptFrame::AddImport(deprecatedNS);
}, 50);
ScriptFrame::ScriptFrame(void)
: Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
ScriptFrame::ScriptFrame(bool allocLocals)
: Locals(allocLocals ? new Dictionary() : nullptr), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
{
InitializeFrame();
}
ScriptFrame::ScriptFrame(const Value& self)
: Locals(new Dictionary()), Self(self), Sandboxed(false), Depth(0)
ScriptFrame::ScriptFrame(const Value& self, bool allocLocals)
: Locals(allocLocals ? new Dictionary() : nullptr), Self(self), Sandboxed(false), Depth(0)
{
InitializeFrame();
}

View File

@ -36,8 +36,8 @@ struct I2_BASE_API ScriptFrame
bool Sandboxed;
int Depth;
ScriptFrame(void);
ScriptFrame(const Value& self);
ScriptFrame(bool allocLocals = true);
ScriptFrame(const Value& self, bool allocLocals = true);
~ScriptFrame(void);
void IncreaseStackDepth(void);

View File

@ -119,6 +119,8 @@ public:
ScriptFrame *frame = ScriptFrame::GetCurrentFrame();
frame->Locals = new Dictionary();
if (evaluatedClosedVars)
evaluatedClosedVars->CopyTo(frame->Locals);