Performance improvements for Value -> double conversions.

This commit is contained in:
Gunnar Beutner 2013-03-27 06:26:42 +00:00
parent 604b57da43
commit babc948cd0
2 changed files with 10 additions and 9 deletions

View File

@ -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

View File

@ -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;