mirror of https://github.com/Icinga/icinga2.git
Performance improvements.
This commit is contained in:
parent
029dc35366
commit
1726e1ba0d
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue