[icinga-checkins] icinga.org: icinga2/master: Performance improvements for Value -> double conversions.

git at icinga.org git at icinga.org
Wed Mar 27 10:56:00 CET 2013


Module: icinga2
Branch: master
Commit: babc948cd03840dc7cdbcd1c07458be11dca356c
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=babc948cd03840dc7cdbcd1c07458be11dca356c

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Wed Mar 27 06:26:42 2013 +0000

Performance improvements for Value -> double conversions.

---

 lib/base/value.cpp |   15 ++++++++-------
 lib/base/value.h   |    4 ++--
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/lib/base/value.cpp b/lib/base/value.cpp
index f4e07b0..556f984 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<double>(m_Value);
-	} else {
-		return boost::get<double>(m_Value);
-	}
+	const double *value = boost::get<double>(&m_Value);
+
+	if (value)
+		return *value;
+
+	return boost::lexical_cast<double>(m_Value);
 }
 
 Value::operator String(void) const
diff --git a/lib/base/value.h b/lib/base/value.h
index 0554a51..e786f27 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<boost::blank, double, String, Object::Ptr> m_Value;
+	boost::variant<boost::blank, double, String, Object::Ptr> m_Value;
 };
 
 static Value Empty;





More information about the icinga-checkins mailing list