]> granicus.if.org Git - icinga2/commitdiff
Avoid unnecessary allocations for script frames 5882/head
authorGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 18 Dec 2017 09:30:20 +0000 (10:30 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 18 Dec 2017 12:40:29 +0000 (13:40 +0100)
lib/base/function.cpp
lib/base/scriptframe.cpp
lib/base/scriptframe.hpp
lib/config/vmops.hpp

index cb34d835fd9abdc8e1f027d92587c580f2a0600e..da2302f6dfe79fbd600d2da1652f28b4d55dbb6a 100644 (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);
 }
 
index 3d41c4ec8bab3b01119bb1af721747e37ffed39e..1576a80b5be908793fd5b204086166b35e259120 100644 (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();
 }
index 25e71823dc26c91bca12b9273d16f9db92ee2d69..06fdad0fdaf8a61ff00eed8c10863c89df63fcd9 100644 (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);
index 5f0c27eac2755552644b32a1b34c6535de415c26..97c5d6358543b23d5524c7db98c217bf623d3576 100644 (file)
@@ -119,6 +119,8 @@ public:
 
                        ScriptFrame *frame = ScriptFrame::GetCurrentFrame();
 
+                       frame->Locals = new Dictionary();
+
                        if (evaluatedClosedVars)
                                evaluatedClosedVars->CopyTo(frame->Locals);