|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81925 - in sandbox-branches/geometry/index: boost/geometry/extensions/index tests
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-13 19:13:20
Author: awulkiew
Date: 2012-12-13 19:13:20 EST (Thu, 13 Dec 2012)
New Revision: 81925
URL: http://svn.boost.org/trac/boost/changeset/81925
Log:
Added optimized uninitialized_copy() and destroy() to static_vector.
Text files modified:
sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp | 55 ++++++++++++++++++++++++++-------------
sandbox-branches/geometry/index/tests/additional_speed.cpp | 6 ++--
2 files changed, 40 insertions(+), 21 deletions(-)
Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp 2012-12-13 19:13:20 EST (Thu, 13 Dec 2012)
@@ -9,6 +9,13 @@
#include <boost/aligned_storage.hpp>
#include <boost/iterator/reverse_iterator.hpp>
+#include <boost/type_traits/alignment_of.hpp>
+#include <boost/type_traits/aligned_storage.hpp>
+#include <boost/type_traits/has_trivial_assign.hpp>
+#include <boost/type_traits/has_trivial_copy.hpp>
+#include <boost/type_traits/has_trivial_constructor.hpp>
+#include <boost/type_traits/has_trivial_destructor.hpp>
+
#include <boost/geometry/extensions/index/assert.hpp>
#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_STATIC_VECTOR_HPP
@@ -43,20 +50,12 @@
// strong
static_vector(static_vector const& other)
- : m_size(0)
{
//BOOST_ASSERT_MSG(other.m_size <= Capacity, "capacity too small");
- try
- {
- for ( ; m_size < other.m_size ; ++m_size )
- this->construct(m_size, other[m_size]); // may throw
- }
- catch(...)
- {
- this->destroy(0, m_size);
- throw; // rethrow
- }
+ this->uninitialized_copy(other.ptr(0), other.ptr(other.m_size), this->ptr(0),
+ boost::has_trivial_copy_constructor<value_type>());
+ m_size = other.m_size;
}
// basic
@@ -197,27 +196,47 @@
bool empty() const { return 0 == m_size; }
private:
- void construct(size_type i)
+ void uninitialized_copy(const value_type * first, const value_type * last, value_type * dst, boost::true_type const&)
{
- new (this->ptr(i)) value_type(); // may throw
+ ::memcpy(dst, first, sizeof(value_type) * std::distance(first, last));
}
- void construct(size_type i, Value const& value)
+ void uninitialized_copy(const value_type * first, const value_type * last, value_type * dst, boost::false_type const&)
{
- new (this->ptr(i)) value_type(value); // may throw
+ std::uninitialized_copy(first, last, dst); // may throw
}
- void destroy(size_type i)
+ void destroy(const value_type * first, const value_type * last, boost::true_type const&)
+ {}
+
+ void destroy(const value_type * first, const value_type * last, boost::false_type const&)
{
- this->ptr(i)->~value_type();
+ for ( ; first != last ; ++first )
+ first->~value_type();
}
+ // old version - remove
void destroy(size_type first_i, size_type last_i)
{
for ( size_type i = first_i ; i < last_i ; ++i )
this->destroy(i);
}
+ void construct(size_type i)
+ {
+ new (this->ptr(i)) value_type(); // may throw
+ }
+
+ void construct(size_type i, Value const& value)
+ {
+ new (this->ptr(i)) value_type(value); // may throw
+ }
+
+ void destroy(size_type i)
+ {
+ this->ptr(i)->~value_type();
+ }
+
Value * ptr(size_type i)
{
return (reinterpret_cast<Value*>(m_storage.address()) + i);
@@ -228,7 +247,7 @@
return (reinterpret_cast<const Value*>(m_storage.address()) + i);
}
- boost::aligned_storage<sizeof(Value[Capacity])> m_storage;
+ boost::aligned_storage<sizeof(Value[Capacity]), boost::alignment_of<Value[Capacity]>::value> m_storage;
size_type m_size;
};
Modified: sandbox-branches/geometry/index/tests/additional_speed.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/additional_speed.cpp (original)
+++ sandbox-branches/geometry/index/tests/additional_speed.cpp 2012-12-13 19:13:20 EST (Thu, 13 Dec 2012)
@@ -30,7 +30,7 @@
namespace bgi = bg::index;
size_t values_count = 1000000;
- size_t queries_count = 1000000;
+ size_t queries_count = 100000;
std::vector< std::pair<float, float> > coords;
@@ -55,11 +55,11 @@
//typedef bg::model::d2::point_xy<double> P;
typedef bg::model::point<double, 2, bg::cs::cartesian> P;
typedef bg::model::box<P> B;
- //typedef bgi::rtree<B, bgi::linear<32, 8> > RT;
+ typedef bgi::rtree<B, bgi::linear<32, 8> > RT;
//typedef bgi::rtree<B, bgi::runtime::linear > RT;
//typedef bgi::rtree<B, bgi::quadratic<32, 8> > RT;
// typedef bgi::rtree<B, bgi::runtime::quadratic > RT;
- typedef bgi::rtree<B, bgi::rstar<32, 8> > RT;
+ //typedef bgi::rtree<B, bgi::rstar<32, 8> > RT;
//typedef bgi::rtree<B, bgi::runtime::rstar > RT;
for ( ;; )
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk