From 662534692280947b9effe8e6ab1785610297ec4e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 3 Dec 2013 09:59:21 +0100 Subject: [PATCH] Speed up config compiler. Fixes #5255 --- lib/base/serializer.cpp | 6 +++-- lib/base/type.h | 4 ++-- lib/config/configitem.cpp | 47 +++++++++++++++++---------------------- lib/config/configitem.h | 6 ++--- lib/config/configtype.cpp | 3 +-- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp index 22156084d..a23450c63 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -167,11 +167,13 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary if ((field.Attributes & attributeTypes) == 0) continue; - if (!input->Contains(field.Name)) + Value value = input->Get(field.Name); + + if (value.IsEmpty()) continue; try { - instance->SetField(i, Deserialize(input->Get(field.Name), attributeTypes)); + instance->SetField(i, Deserialize(value, attributeTypes)); } catch (const std::exception&) { instance->SetField(i, Empty); } diff --git a/lib/base/type.h b/lib/base/type.h index 0821247b9..b508a1538 100644 --- a/lib/base/type.h +++ b/lib/base/type.h @@ -32,10 +32,10 @@ namespace icinga struct Field { int ID; - String Name; + const char *Name; int Attributes; - Field(int id, const String& name, int attributes) + Field(int id, const char *name, int attributes) : ID(id), Name(name), Attributes(attributes) { } }; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 3e8bc90c5..b7287331b 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -105,6 +105,9 @@ void ConfigItem::Link(void) { ObjectLock olock(this); + if (m_LinkedExpressionList) + return; + m_LinkedExpressionList = make_shared(); BOOST_FOREACH(const String& name, m_ParentNames) { @@ -118,7 +121,7 @@ void ConfigItem::Link(void) } else { parent->Link(); - ExpressionList::Ptr pexprl = parent->GetLinkedExpressionList(); + ExpressionList::Ptr pexprl = parent->m_LinkedExpressionList; m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, pexprl, m_DebugInfo)); } } @@ -126,15 +129,26 @@ void ConfigItem::Link(void) m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, m_ExpressionList, m_DebugInfo)); } -ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void) const +ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void) { - ObjectLock olock(this); + if (!m_LinkedExpressionList) + Link(); return m_LinkedExpressionList; } +Dictionary::Ptr ConfigItem::GetProperties(void) +{ + if (!m_Properties) { + m_Properties = make_shared(); + GetLinkedExpressionList()->Execute(m_Properties); + } + + return m_Properties; +} + /** - * Commits the configuration item by creating or updating a DynamicObject + * Commits the configuration item by creating a DynamicObject * object. * * @returns The DynamicObject that was created/updated. @@ -157,24 +171,9 @@ DynamicObject::Ptr ConfigItem::Commit(void) if (IsAbstract()) return DynamicObject::Ptr(); - /* Create a fake update in the format that - * DynamicObject::Deserialize expects. */ - Dictionary::Ptr attrs = make_shared(); - - Link(); - - Dictionary::Ptr properties = make_shared(); - GetLinkedExpressionList()->Execute(properties); + Dictionary::Ptr properties = GetProperties(); - { - ObjectLock olock(properties); - - BOOST_FOREACH(const Dictionary::Pair& kv, properties) { - attrs->Set(kv.first, kv.second); - } - } - - DynamicObject::Ptr dobj = dtype->CreateObject(attrs); + DynamicObject::Ptr dobj = dtype->CreateObject(properties); dobj->Register(); return dobj; @@ -238,12 +237,6 @@ bool ConfigItem::ActivateItems(bool validateOnly) if (ConfigCompilerContext::GetInstance()->HasErrors()) return false; - Log(LogInformation, "config", "Linking config items..."); - - BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) { - kv.second->Link(); - } - if (ConfigCompilerContext::GetInstance()->HasErrors()) return false; diff --git a/lib/config/configitem.h b/lib/config/configitem.h index 6109f840c..98a65fdf2 100644 --- a/lib/config/configitem.h +++ b/lib/config/configitem.h @@ -48,9 +48,8 @@ public: std::vector GetParents(void) const; void Link(void); - ExpressionList::Ptr GetLinkedExpressionList(void) const; - - void GetProperties(void); + ExpressionList::Ptr GetLinkedExpressionList(void); + Dictionary::Ptr GetProperties(void); DynamicObject::Ptr Commit(void); void Register(void); @@ -79,6 +78,7 @@ private: DebugInfo m_DebugInfo; /**< Debug information. */ ExpressionList::Ptr m_LinkedExpressionList; + Dictionary::Ptr m_Properties; static boost::mutex m_Mutex; diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp index 3174e9516..5c18ddcfa 100644 --- a/lib/config/configtype.cpp +++ b/lib/config/configtype.cpp @@ -79,8 +79,7 @@ void ConfigType::ValidateItem(const ConfigItem::Ptr& item) if (item->IsAbstract()) return; - Dictionary::Ptr attrs = make_shared(); - item->GetLinkedExpressionList()->Execute(attrs); + Dictionary::Ptr attrs = item->GetProperties(); std::vector locations; DebugInfo debugInfo = item->GetDebugInfo(); -- 2.40.0