mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
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)
|
Value Function::Invoke(const std::vector<Value>& arguments)
|
||||||
{
|
{
|
||||||
ScriptFrame frame;
|
ScriptFrame frame(false);
|
||||||
return m_Callback(arguments);
|
return m_Callback(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Function::InvokeThis(const Value& otherThis, const std::vector<Value>& arguments)
|
Value Function::InvokeThis(const Value& otherThis, const std::vector<Value>& arguments)
|
||||||
{
|
{
|
||||||
ScriptFrame frame;
|
ScriptFrame frame(otherThis, false);
|
||||||
frame.Self = otherThis;
|
|
||||||
return m_Callback(arguments);
|
return m_Callback(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
|
|||||||
ScriptFrame::AddImport(deprecatedNS);
|
ScriptFrame::AddImport(deprecatedNS);
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
ScriptFrame::ScriptFrame(void)
|
ScriptFrame::ScriptFrame(bool allocLocals)
|
||||||
: Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
|
: Locals(allocLocals ? new Dictionary() : nullptr), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
|
||||||
{
|
{
|
||||||
InitializeFrame();
|
InitializeFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFrame::ScriptFrame(const Value& self)
|
ScriptFrame::ScriptFrame(const Value& self, bool allocLocals)
|
||||||
: Locals(new Dictionary()), Self(self), Sandboxed(false), Depth(0)
|
: Locals(allocLocals ? new Dictionary() : nullptr), Self(self), Sandboxed(false), Depth(0)
|
||||||
{
|
{
|
||||||
InitializeFrame();
|
InitializeFrame();
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ struct I2_BASE_API ScriptFrame
|
|||||||
bool Sandboxed;
|
bool Sandboxed;
|
||||||
int Depth;
|
int Depth;
|
||||||
|
|
||||||
ScriptFrame(void);
|
ScriptFrame(bool allocLocals = true);
|
||||||
ScriptFrame(const Value& self);
|
ScriptFrame(const Value& self, bool allocLocals = true);
|
||||||
~ScriptFrame(void);
|
~ScriptFrame(void);
|
||||||
|
|
||||||
void IncreaseStackDepth(void);
|
void IncreaseStackDepth(void);
|
||||||
|
@ -119,6 +119,8 @@ public:
|
|||||||
|
|
||||||
ScriptFrame *frame = ScriptFrame::GetCurrentFrame();
|
ScriptFrame *frame = ScriptFrame::GetCurrentFrame();
|
||||||
|
|
||||||
|
frame->Locals = new Dictionary();
|
||||||
|
|
||||||
if (evaluatedClosedVars)
|
if (evaluatedClosedVars)
|
||||||
evaluatedClosedVars->CopyTo(frame->Locals);
|
evaluatedClosedVars->CopyTo(frame->Locals);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user