]> granicus.if.org Git - icinga2/commitdiff
Avoid unnecessary dictionary lookups
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 1 Sep 2016 05:41:41 +0000 (07:41 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 1 Sep 2016 05:41:41 +0000 (07:41 +0200)
refs #12555

lib/base/dictionary.cpp
lib/base/dictionary.hpp
lib/base/object.cpp
lib/base/object.hpp
lib/config/expression.cpp

index e3b348fa6a7c49423317719a515811d0f46ee9c7..2c7cba668879f6e88c7805172aec7057e30b69b5 100644 (file)
@@ -228,3 +228,8 @@ bool Dictionary::HasOwnField(const String& field) const
 {
        return Contains(field);
 }
+
+bool Dictionary::GetOwnField(const String& field, Value *result) const
+{
+       return Get(field, result);
+}
index edacaa244e85ddc027ef3e4699c668b2ca5811e0..f5b524753ab86eef3d290340d35fee7d99a996e1 100644 (file)
@@ -121,6 +121,7 @@ public:
        virtual Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
        virtual void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
        virtual bool HasOwnField(const String& field) const override;
+       virtual bool GetOwnField(const String& field, Value *result) const override;
 
 private:
        std::map<String, Value> m_Data; /**< The data for the dictionary. */
index 3ac220df3d72d2b16d0e9fa0788e64a82c908b77..a93aad774dbabfe7618fccad082e8cea31f66698 100644 (file)
@@ -109,6 +109,22 @@ bool Object::HasOwnField(const String& field) const
        return type->GetFieldId(field) != -1;
 }
 
+bool Object::GetOwnField(const String& field, Value *result) const
+{
+       Type::Ptr type = GetReflectionType();
+
+       if (!type)
+               return false;
+
+       int tid = type->GetFieldId(field);
+
+       if (tid == -1)
+               return false;
+
+       *result = GetField(tid);
+       return true;
+}
+
 Value Object::GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const
 {
        Type::Ptr type = GetReflectionType();
index 942764c2522c59416a87f40367fae778ae23af57..595773a4e63cdb1f2c1e23ff6e7456fad2e8d2a3 100644 (file)
@@ -127,6 +127,7 @@ public:
        virtual Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const;
        virtual void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo);
        virtual bool HasOwnField(const String& field) const;
+       virtual bool GetOwnField(const String& field, Value *result) const;
        virtual void ValidateField(int id, const Value& value, const ValidationUtils& utils);
        virtual void NotifyField(int id, const Value& cookie = Empty);
        virtual Object::Ptr NavigateField(int id) const;
index 0930a91299e18d1a0a39c79190966cc7e9be2fa4..8b23b67e54920a860f31ffbe2e5ef21b537338b0 100644 (file)
@@ -121,8 +121,8 @@ ExpressionResult VariableExpression::DoEvaluate(ScriptFrame& frame, DebugHint *d
 
        if (frame.Locals && frame.Locals->Get(m_Variable, &value))
                return value;
-       else if (frame.Self.IsObject() && frame.Locals != static_cast<Object::Ptr>(frame.Self) && static_cast<Object::Ptr>(frame.Self)->HasOwnField(m_Variable))
-               return VMOps::GetField(frame.Self, m_Variable, frame.Sandboxed, m_DebugInfo);
+       else if (frame.Self.IsObject() && frame.Locals != frame.Self.Get<Object::Ptr>() && frame.Self.Get<Object::Ptr>()->GetOwnField(m_Variable, &value))
+               return value;
        else if (VMOps::FindVarImport(frame, m_Variable, &value, m_DebugInfo))
                return value;
        else
@@ -138,7 +138,7 @@ bool VariableExpression::GetReference(ScriptFrame& frame, bool init_dict, Value
 
                if (dhint)
                        *dhint = NULL;
-       } else if (frame.Self.IsObject() && frame.Locals != static_cast<Object::Ptr>(frame.Self) && static_cast<Object::Ptr>(frame.Self)->HasOwnField(m_Variable)) {
+       } else if (frame.Self.IsObject() && frame.Locals != frame.Self.Get<Object::Ptr>() && frame.Self.Get<Object::Ptr>()->HasOwnField(m_Variable)) {
                *parent = frame.Self;
 
                if (dhint && *dhint)