]> granicus.if.org Git - icinga2/commitdiff
Performance improvements.
authorGunnar Beutner <gunnar@beutner.name>
Mon, 11 Jun 2012 06:21:47 +0000 (08:21 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 11 Jun 2012 06:21:47 +0000 (08:21 +0200)
base/dictionary.h
dyn/configcompiler.cpp
dyn/configcompiler.h
dyn/configitem.cpp
dyn/configitem.h
dyn/expression.cpp
dyn/expression.h
dyntest/dyntest.cpp

index 7af0cf844fab5c17a4079abdbca4e0b0ccab78d4..549d4c74a1620c1b5bb1552670fdfde67240beb1 100644 (file)
@@ -45,7 +45,7 @@ public:
         * @returns true if the value was retrieved, false otherwise.
         */
        template<typename T>
-       bool GetProperty(string key, T *value) const
+       bool GetProperty(const string& key, T *value) const
        {
                ConstDictionaryIterator i = m_Data.find(key);
 
@@ -64,7 +64,7 @@ public:
         * @param[out] value Pointer to the value.
         * @returns true if the value was retrieved, false otherwise.
         */
-       bool GetProperty(string key, Dictionary::Ptr *value)
+       bool GetProperty(const string& key, Dictionary::Ptr *value)
        {
                Object::Ptr object;
 
@@ -85,7 +85,7 @@ public:
         * @param value The value.
         */
        template<typename T>
-       void SetProperty(string key, const T& value)
+       void SetProperty(const string& key, const T& value)
        {
                pair<typename map<string, Variant>::iterator, bool> ret;
                ret = m_Data.insert(make_pair(key, value));
index e236dacb416ec8e48f9f60ac9c85f07a53ea97bb..090015226e6c574cd30584bc028748cb50d8e107 100644 (file)
@@ -60,14 +60,14 @@ vector<ConfigItem::Ptr> ConfigCompiler::CompileStream(istream *stream)
        return ctx.GetResult();
 }
 
-vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(string filename)
+vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(const string& filename)
 {
        ifstream stream;
        stream.open(filename, ifstream::in);
        return CompileStream(&stream);
 }
 
-vector<ConfigItem::Ptr> ConfigCompiler::CompileText(string text)
+vector<ConfigItem::Ptr> ConfigCompiler::CompileText(const string& text)
 {
        stringstream stream(text);
        return CompileStream(&stream);
index 8b1f353cd0f41e22096bef9a20d182d72dd26bea..1ef3a5fd469c5adfa62518728da1ac0935ed95d7 100644 (file)
@@ -32,8 +32,8 @@ public:
        void Compile(void);
 
        static vector<ConfigItem::Ptr> CompileStream(istream *stream);
-       static vector<ConfigItem::Ptr> CompileFile(string filename);
-       static vector<ConfigItem::Ptr> CompileText(string text);
+       static vector<ConfigItem::Ptr> CompileFile(const string& filename);
+       static vector<ConfigItem::Ptr> CompileText(const string& text);
 
        void SetResult(vector<ConfigItem::Ptr> result);
        vector<ConfigItem::Ptr> GetResult(void) const;
index 1b7e6d8706ba5c1f1462c0fb53121fc0abe27a7a..fbc77c111f932817c10cfd2492f1354cbd1cf4cc 100644 (file)
@@ -21,7 +21,7 @@
 
 using namespace icinga;
 
-ConfigItem::ConfigItem(string type, string name, DebugInfo debuginfo)
+ConfigItem::ConfigItem(const string& type, const string& name, const DebugInfo& debuginfo)
        : m_Type(type), m_Name(name), m_DebugInfo(debuginfo)
 {
 }
@@ -51,7 +51,7 @@ vector<string> ConfigItem::GetParents(void) const
        return m_Parents;
 }
 
-void ConfigItem::AddParent(string parent)
+void ConfigItem::AddParent(const string& parent)
 {
        m_Parents.push_back(parent);
 }
@@ -140,7 +140,7 @@ void ConfigItem::Unregister(void)
        GetAllObjects()->RemoveObject(self);
 }
 
-ConfigItem::Ptr ConfigItem::GetObject(string type, string name)
+ConfigItem::Ptr ConfigItem::GetObject(const string& type, const string& name)
 {
        ConfigItem::TNMap::Range range;
        range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name));
index d2cdaefdf8b8a96c4b4603f6d5b7e4767aa6b2f4..4e85f9a29e0fc0bf018db0f2734b7cc28d10aa87 100644 (file)
@@ -30,13 +30,13 @@ public:
 
        typedef ObjectMap<pair<string, string>, ConfigItem::Ptr> TNMap;
 
-       ConfigItem(string type, string name, DebugInfo debuginfo);
+       ConfigItem(const string& type, const string& name, const DebugInfo& debuginfo);
 
        string GetType(void) const;
        string GetName(void) const;
 
        vector<string> GetParents(void) const;
-       void AddParent(string parent);
+       void AddParent(const string& parent);
 
        ExpressionList::Ptr GetExpressionList(void) const;
        void SetExpressionList(const ExpressionList::Ptr& exprl);
@@ -48,7 +48,7 @@ public:
 
        static ObjectSet<ConfigItem::Ptr>::Ptr GetAllObjects(void);
        static TNMap::Ptr GetObjectsByTypeAndName(void);
-       static ConfigItem::Ptr GetObject(string type, string name);
+       static ConfigItem::Ptr GetObject(const string& type, const string& name);
 
 private:
        string m_Type;
@@ -62,7 +62,6 @@ private:
        static bool GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key);
 };
 
-
 }
 
 #endif /* CONFIGITEM_H */
index 5a0ed6bb3e1e5fb6e9c0d1d07991b5bf02f39b28..4c7b08ac8a5f9bf7f0283bbe0423201d075e4bf1 100644 (file)
@@ -21,7 +21,7 @@
 
 using namespace icinga;
 
-Expression::Expression(string key, ExpressionOperator op, const Variant& value, const DebugInfo& debuginfo)
+Expression::Expression(const string& key, ExpressionOperator op, const Variant& value, const DebugInfo& debuginfo)
        : m_Key(key), m_Operator(op), m_Value(value), m_DebugInfo(debuginfo)
 {
 }
@@ -29,7 +29,6 @@ Expression::Expression(string key, ExpressionOperator op, const Variant& value,
 void Expression::Execute(const Dictionary::Ptr& dictionary) const
 {
        Variant oldValue, newValue;
-       dictionary->GetProperty(m_Key, &oldValue);
 
        ExpressionList::Ptr exprl;
        if (m_Value.GetType() == VariantObject)
@@ -49,6 +48,8 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
 
                case OperatorPlus:
                        if (exprl) {
+                               dictionary->GetProperty(m_Key, &oldValue);
+
                                Dictionary::Ptr dict;
                                if (oldValue.GetType() == VariantObject)
                                        dict = dynamic_pointer_cast<Dictionary>(oldValue.GetObject());
index e6ec75eae3522ed7acd2fa951cabf720b291904e..4b70a65fb900f02edae651be4c03f838e9d7e8eb 100644 (file)
@@ -35,7 +35,7 @@ enum ExpressionOperator
 struct I2_DYN_API Expression
 {
 public:
-       Expression(string key, ExpressionOperator op, const Variant& value, const DebugInfo& debuginfo);
+       Expression(const string& key, ExpressionOperator op, const Variant& value, const DebugInfo& debuginfo);
 
        void Execute(const Dictionary::Ptr& dictionary) const;
 
index ffc63ffa3923b23d2c4ecadfa90686ea51454209..3ac8a15a716480096f23237160f54ee341471c63 100644 (file)
@@ -10,13 +10,13 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       for (int i = 0; i < 10000; i++) {
+       for (int i = 0; i < 1; i++) {
                vector<ConfigItem::Ptr> objects = ConfigCompiler::CompileFile(string(argv[1]));
 
                ConfigVM::ExecuteItems(objects);
        }
 
-       ObjectSet<DynamicObject::Ptr>::Iterator it;
+/*     ObjectSet<DynamicObject::Ptr>::Iterator it;
        for (it = DynamicObject::GetAllObjects()->Begin(); it != DynamicObject::GetAllObjects()->End(); it++) {
                DynamicObject::Ptr obj = *it;
                cout << "Object, name: " << obj->GetName() << ", type: " << obj->GetType() << endl;
@@ -24,6 +24,6 @@ int main(int argc, char **argv)
                MessagePart mp(obj->GetConfig());
                cout << mp.ToJsonString() << endl;
        }
-
+*/
        return 0;
 }