From: Gunnar Beutner Date: Wed, 27 Mar 2013 06:26:42 +0000 (+0000) Subject: Performance improvements for Value -> double conversions. X-Git-Tag: v0.0.2~175 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=babc948cd03840dc7cdbcd1c07458be11dca356c;p=icinga2 Performance improvements for Value -> double conversions. --- diff --git a/lib/base/value.cpp b/lib/base/value.cpp index f4e07b0cc..556f98482 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -59,7 +59,7 @@ Value::Value(const char *value) */ bool Value::IsEmpty(void) const { - return (m_Value.type() == typeid(boost::blank)); + return (GetType() == ValueEmpty); } /** @@ -79,16 +79,17 @@ bool Value::IsScalar(void) const */ bool Value::IsObject(void) const { - return !IsEmpty() && (m_Value.type() == typeid(Object::Ptr)); + return !IsEmpty() && (GetType() == ValueObject); } Value::operator double(void) const { - if (m_Value.type() != typeid(double)) { - return boost::lexical_cast(m_Value); - } else { - return boost::get(m_Value); - } + const double *value = boost::get(&m_Value); + + if (value) + return *value; + + return boost::lexical_cast(m_Value); } Value::operator String(void) const diff --git a/lib/base/value.h b/lib/base/value.h index 0554a5178..e786f2719 100644 --- a/lib/base/value.h +++ b/lib/base/value.h @@ -85,7 +85,7 @@ public: return object; } -bool IsEmpty(void) const; + bool IsEmpty(void) const; bool IsScalar(void) const; bool IsObject(void) const; @@ -107,7 +107,7 @@ bool IsEmpty(void) const; ValueType GetType(void) const; private: - mutable boost::variant m_Value; + boost::variant m_Value; }; static Value Empty;