From eb746b9929f451399a48bf6860362bffa42752b4 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 11 Nov 2013 08:22:58 +0100 Subject: [PATCH] Optimize DynamicObject::HasAuthority(). Refs #5049 --- components/checker/checkercomponent.h | 3 --- lib/base/dynamicobject.cpp | 5 ++++- lib/base/dynamicobject.ti | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index b0e9a2f23..a3f1e69e2 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -47,9 +47,6 @@ struct ServiceNextCheckExtractor */ double operator()(const Service::Ptr& service) { - if (!service->HasAuthority("checker")) - return Utility::GetTime() + 60; - return service->GetNextCheck(); } }; diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index ba7f52c08..2bd119eb5 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -74,6 +74,9 @@ void DynamicObject::SetAuthority(const String& type, bool value) if (old_value == value) return; + if (GetAuthorityInfo() == NULL) + SetAuthorityInfo(make_shared()); + GetAuthorityInfo()->Set(type, value); } @@ -84,7 +87,7 @@ bool DynamicObject::HasAuthority(const String& type) const { Dictionary::Ptr authorityInfo = GetAuthorityInfo(); - if (!authorityInfo->Contains(type)) + if (!authorityInfo || !authorityInfo->Contains(type)) return true; return authorityInfo->Get(type); diff --git a/lib/base/dynamicobject.ti b/lib/base/dynamicobject.ti index faf1c4a78..bbf361e73 100644 --- a/lib/base/dynamicobject.ti +++ b/lib/base/dynamicobject.ti @@ -10,9 +10,7 @@ abstract class DynamicObject [config] Array::Ptr domains; [config] Array::Ptr authorities; [get_protected] bool active; - Dictionary::Ptr authority_info { - default {{{ return make_shared(); }}} - }; + Dictionary::Ptr authority_info; [protected] Dictionary::Ptr extensions; }; -- 2.40.0