Revert "Use unique_ptr instead of shared_ptr in our any implementation, >10% speed improvement"

This reverts commit f27739cf71.
This commit is contained in:
Jason Turner
2012-07-13 13:54:48 -06:00
parent c2934caad6
commit 7052234650

View File

@@ -44,7 +44,7 @@ namespace chaiscript {
{ {
virtual void *data() = 0; virtual void *data() = 0;
virtual const std::type_info &type() const = 0; virtual const std::type_info &type() const = 0;
virtual std::unique_ptr<Data> clone() const = 0; virtual std::shared_ptr<Data> clone() const = 0;
}; };
template<typename T> template<typename T>
@@ -66,16 +66,16 @@ namespace chaiscript {
return m_type; return m_type;
} }
std::unique_ptr<Data> clone() const std::shared_ptr<Data> clone() const
{ {
return std::unique_ptr<Data>(new Data_Impl<T>(m_data)); return std::shared_ptr<Data>(new Data_Impl<T>(m_data));
} }
const std::type_info &m_type; const std::type_info &m_type;
T m_data; T m_data;
}; };
std::unique_ptr<Data> m_data; std::shared_ptr<Data> m_data;
public: public:
// construct/copy/destruct // construct/copy/destruct
@@ -94,7 +94,7 @@ namespace chaiscript {
template<typename ValueType> template<typename ValueType>
Any(const ValueType &t_value) Any(const ValueType &t_value)
{ {
m_data = std::unique_ptr<Data>(new Data_Impl<ValueType>(t_value)); m_data = std::shared_ptr<Data>(new Data_Impl<ValueType>(t_value));
} }
Any & operator=(const Any &t_any) Any & operator=(const Any &t_any)
@@ -131,7 +131,9 @@ namespace chaiscript {
// modifiers // modifiers
Any & swap(Any &t_other) Any & swap(Any &t_other)
{ {
std::swap(m_data, t_other.m_data); std::shared_ptr<Data> data = t_other.m_data;
t_other.m_data = m_data;
m_data = data;
return *this; return *this;
} }