mirror of https://github.com/Icinga/icinga2.git
Avoid unnecessary allocations for script frames
This commit is contained in:
parent
80b72cfb1c
commit
4866f777cc
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -119,6 +119,8 @@ public:
|
|||
|
||||
ScriptFrame *frame = ScriptFrame::GetCurrentFrame();
|
||||
|
||||
frame->Locals = new Dictionary();
|
||||
|
||||
if (evaluatedClosedVars)
|
||||
evaluatedClosedVars->CopyTo(frame->Locals);
|
||||
|
||||
|
|
Loading…
Reference in New Issue