Performance improvements.

This commit is contained in:
Gunnar Beutner 2012-06-11 08:21:47 +02:00
parent 029dc35366
commit 1726e1ba0d
8 changed files with 20 additions and 20 deletions

View File

@ -45,7 +45,7 @@ public:
* @returns true if the value was retrieved, false otherwise. * @returns true if the value was retrieved, false otherwise.
*/ */
template<typename T> template<typename T>
bool GetProperty(string key, T *value) const bool GetProperty(const string& key, T *value) const
{ {
ConstDictionaryIterator i = m_Data.find(key); ConstDictionaryIterator i = m_Data.find(key);
@ -64,7 +64,7 @@ public:
* @param[out] value Pointer to the value. * @param[out] value Pointer to the value.
* @returns true if the value was retrieved, false otherwise. * @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; Object::Ptr object;
@ -85,7 +85,7 @@ public:
* @param value The value. * @param value The value.
*/ */
template<typename T> 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; pair<typename map<string, Variant>::iterator, bool> ret;
ret = m_Data.insert(make_pair(key, value)); ret = m_Data.insert(make_pair(key, value));

View File

@ -60,14 +60,14 @@ vector<ConfigItem::Ptr> ConfigCompiler::CompileStream(istream *stream)
return ctx.GetResult(); return ctx.GetResult();
} }
vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(string filename) vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(const string& filename)
{ {
ifstream stream; ifstream stream;
stream.open(filename, ifstream::in); stream.open(filename, ifstream::in);
return CompileStream(&stream); return CompileStream(&stream);
} }
vector<ConfigItem::Ptr> ConfigCompiler::CompileText(string text) vector<ConfigItem::Ptr> ConfigCompiler::CompileText(const string& text)
{ {
stringstream stream(text); stringstream stream(text);
return CompileStream(&stream); return CompileStream(&stream);

View File

@ -32,8 +32,8 @@ public:
void Compile(void); void Compile(void);
static vector<ConfigItem::Ptr> CompileStream(istream *stream); static vector<ConfigItem::Ptr> CompileStream(istream *stream);
static vector<ConfigItem::Ptr> CompileFile(string filename); static vector<ConfigItem::Ptr> CompileFile(const string& filename);
static vector<ConfigItem::Ptr> CompileText(string text); static vector<ConfigItem::Ptr> CompileText(const string& text);
void SetResult(vector<ConfigItem::Ptr> result); void SetResult(vector<ConfigItem::Ptr> result);
vector<ConfigItem::Ptr> GetResult(void) const; vector<ConfigItem::Ptr> GetResult(void) const;

View File

@ -21,7 +21,7 @@
using namespace icinga; 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) : m_Type(type), m_Name(name), m_DebugInfo(debuginfo)
{ {
} }
@ -51,7 +51,7 @@ vector<string> ConfigItem::GetParents(void) const
return m_Parents; return m_Parents;
} }
void ConfigItem::AddParent(string parent) void ConfigItem::AddParent(const string& parent)
{ {
m_Parents.push_back(parent); m_Parents.push_back(parent);
} }
@ -140,7 +140,7 @@ void ConfigItem::Unregister(void)
GetAllObjects()->RemoveObject(self); 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; ConfigItem::TNMap::Range range;
range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name)); range = GetObjectsByTypeAndName()->GetRange(make_pair(type, name));

View File

@ -30,13 +30,13 @@ public:
typedef ObjectMap<pair<string, string>, ConfigItem::Ptr> TNMap; 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 GetType(void) const;
string GetName(void) const; string GetName(void) const;
vector<string> GetParents(void) const; vector<string> GetParents(void) const;
void AddParent(string parent); void AddParent(const string& parent);
ExpressionList::Ptr GetExpressionList(void) const; ExpressionList::Ptr GetExpressionList(void) const;
void SetExpressionList(const ExpressionList::Ptr& exprl); void SetExpressionList(const ExpressionList::Ptr& exprl);
@ -48,7 +48,7 @@ public:
static ObjectSet<ConfigItem::Ptr>::Ptr GetAllObjects(void); static ObjectSet<ConfigItem::Ptr>::Ptr GetAllObjects(void);
static TNMap::Ptr GetObjectsByTypeAndName(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: private:
string m_Type; string m_Type;
@ -62,7 +62,6 @@ private:
static bool GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key); static bool GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key);
}; };
} }
#endif /* CONFIGITEM_H */ #endif /* CONFIGITEM_H */

View File

@ -21,7 +21,7 @@
using namespace icinga; 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) : 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 void Expression::Execute(const Dictionary::Ptr& dictionary) const
{ {
Variant oldValue, newValue; Variant oldValue, newValue;
dictionary->GetProperty(m_Key, &oldValue);
ExpressionList::Ptr exprl; ExpressionList::Ptr exprl;
if (m_Value.GetType() == VariantObject) if (m_Value.GetType() == VariantObject)
@ -49,6 +48,8 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
case OperatorPlus: case OperatorPlus:
if (exprl) { if (exprl) {
dictionary->GetProperty(m_Key, &oldValue);
Dictionary::Ptr dict; Dictionary::Ptr dict;
if (oldValue.GetType() == VariantObject) if (oldValue.GetType() == VariantObject)
dict = dynamic_pointer_cast<Dictionary>(oldValue.GetObject()); dict = dynamic_pointer_cast<Dictionary>(oldValue.GetObject());

View File

@ -35,7 +35,7 @@ enum ExpressionOperator
struct I2_DYN_API Expression struct I2_DYN_API Expression
{ {
public: 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; void Execute(const Dictionary::Ptr& dictionary) const;

View File

@ -10,13 +10,13 @@ int main(int argc, char **argv)
return 1; 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])); vector<ConfigItem::Ptr> objects = ConfigCompiler::CompileFile(string(argv[1]));
ConfigVM::ExecuteItems(objects); ConfigVM::ExecuteItems(objects);
} }
ObjectSet<DynamicObject::Ptr>::Iterator it; /* ObjectSet<DynamicObject::Ptr>::Iterator it;
for (it = DynamicObject::GetAllObjects()->Begin(); it != DynamicObject::GetAllObjects()->End(); it++) { for (it = DynamicObject::GetAllObjects()->Begin(); it != DynamicObject::GetAllObjects()->End(); it++) {
DynamicObject::Ptr obj = *it; DynamicObject::Ptr obj = *it;
cout << "Object, name: " << obj->GetName() << ", type: " << obj->GetType() << endl; cout << "Object, name: " << obj->GetName() << ", type: " << obj->GetType() << endl;
@ -24,6 +24,6 @@ int main(int argc, char **argv)
MessagePart mp(obj->GetConfig()); MessagePart mp(obj->GetConfig());
cout << mp.ToJsonString() << endl; cout << mp.ToJsonString() << endl;
} }
*/
return 0; return 0;
} }