From 1726e1ba0d0880635f4f18e81f0b2957103c1644 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 11 Jun 2012 08:21:47 +0200 Subject: [PATCH] Performance improvements. --- base/dictionary.h | 6 +++--- dyn/configcompiler.cpp | 4 ++-- dyn/configcompiler.h | 4 ++-- dyn/configitem.cpp | 6 +++--- dyn/configitem.h | 7 +++---- dyn/expression.cpp | 5 +++-- dyn/expression.h | 2 +- dyntest/dyntest.cpp | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/base/dictionary.h b/base/dictionary.h index 7af0cf844..549d4c74a 100644 --- a/base/dictionary.h +++ b/base/dictionary.h @@ -45,7 +45,7 @@ public: * @returns true if the value was retrieved, false otherwise. */ template - 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 - void SetProperty(string key, const T& value) + void SetProperty(const string& key, const T& value) { pair::iterator, bool> ret; ret = m_Data.insert(make_pair(key, value)); diff --git a/dyn/configcompiler.cpp b/dyn/configcompiler.cpp index e236dacb4..090015226 100644 --- a/dyn/configcompiler.cpp +++ b/dyn/configcompiler.cpp @@ -60,14 +60,14 @@ vector ConfigCompiler::CompileStream(istream *stream) return ctx.GetResult(); } -vector ConfigCompiler::CompileFile(string filename) +vector ConfigCompiler::CompileFile(const string& filename) { ifstream stream; stream.open(filename, ifstream::in); return CompileStream(&stream); } -vector ConfigCompiler::CompileText(string text) +vector ConfigCompiler::CompileText(const string& text) { stringstream stream(text); return CompileStream(&stream); diff --git a/dyn/configcompiler.h b/dyn/configcompiler.h index 8b1f353cd..1ef3a5fd4 100644 --- a/dyn/configcompiler.h +++ b/dyn/configcompiler.h @@ -32,8 +32,8 @@ public: void Compile(void); static vector CompileStream(istream *stream); - static vector CompileFile(string filename); - static vector CompileText(string text); + static vector CompileFile(const string& filename); + static vector CompileText(const string& text); void SetResult(vector result); vector GetResult(void) const; diff --git a/dyn/configitem.cpp b/dyn/configitem.cpp index 1b7e6d870..fbc77c111 100644 --- a/dyn/configitem.cpp +++ b/dyn/configitem.cpp @@ -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 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)); diff --git a/dyn/configitem.h b/dyn/configitem.h index d2cdaefdf..4e85f9a29 100644 --- a/dyn/configitem.h +++ b/dyn/configitem.h @@ -30,13 +30,13 @@ public: typedef ObjectMap, 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 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::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 *key); }; - } #endif /* CONFIGITEM_H */ diff --git a/dyn/expression.cpp b/dyn/expression.cpp index 5a0ed6bb3..4c7b08ac8 100644 --- a/dyn/expression.cpp +++ b/dyn/expression.cpp @@ -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(oldValue.GetObject()); diff --git a/dyn/expression.h b/dyn/expression.h index e6ec75eae..4b70a65fb 100644 --- a/dyn/expression.h +++ b/dyn/expression.h @@ -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; diff --git a/dyntest/dyntest.cpp b/dyntest/dyntest.cpp index ffc63ffa3..3ac8a15a7 100644 --- a/dyntest/dyntest.cpp +++ b/dyntest/dyntest.cpp @@ -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 objects = ConfigCompiler::CompileFile(string(argv[1])); ConfigVM::ExecuteItems(objects); } - ObjectSet::Iterator it; +/* ObjectSet::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; } -- 2.40.0