[GIT] ppl/ppl(master): For naming consistency, `coefficient_allocator' renamed as `data_allocator'.

Module: ppl/ppl Branch: master Commit: b6bcf0a3f859871de9fb397308bb705a11440e38 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=b6bcf0a3f8598...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Mon Feb 13 14:49:04 2012 +0100
For naming consistency, `coefficient_allocator' renamed as `data_allocator'. Explicitly include <memory> for std::allocator. Fixed deallocation bugs in CO_Tree::rebuild_bigger_tree(): - use delete[] for `indexes'; - use data_allocator.deallocayte for `data'. On copy construction, assignment and swap, do also copy/assign/swap the allocator.
---
src/CO_Tree.cc | 17 ++++++++--------- src/CO_Tree.defs.hh | 10 ++++++---- src/CO_Tree.inlines.hh | 16 +++++----------- 3 files changed, 19 insertions(+), 24 deletions(-)
diff --git a/src/CO_Tree.cc b/src/CO_Tree.cc index 68f9fe0..fc79a0b 100644 --- a/src/CO_Tree.cc +++ b/src/CO_Tree.cc @@ -521,9 +521,9 @@ PPL::CO_Tree::init(dimension_type reserved_size1) { reserved_size = ((dimension_type)1 << max_depth) - 1; indexes = new dimension_type[reserved_size + 2]; try { - data = coefficient_allocator.allocate(reserved_size + 1); + data = data_allocator.allocate(reserved_size + 1); } catch (...) { - delete [] indexes; + delete[] indexes; throw; } // Mark all pairs as unused. @@ -549,8 +549,8 @@ PPL::CO_Tree::destroy() { data[i].~data_type(); }
- delete [] indexes; - coefficient_allocator.deallocate(data, reserved_size + 1); + delete[] indexes; + data_allocator.deallocate(data, reserved_size + 1); } }
@@ -704,9 +704,9 @@ PPL::CO_Tree::rebuild_bigger_tree() { data_type* new_data;
try { - new_data = coefficient_allocator.allocate(new_reserved_size + 1); + new_data = data_allocator.allocate(new_reserved_size + 1); } catch (...) { - delete new_indexes; + delete[] new_indexes; throw; }
@@ -724,8 +724,8 @@ PPL::CO_Tree::rebuild_bigger_tree() { new_indexes[0] = 0; new_indexes[new_reserved_size + 1] = 0;
- delete [] indexes; - operator delete(data); + delete[] indexes; + data_allocator.deallocate(data, reserved_size + 1);
indexes = new_indexes; data = new_data; @@ -1089,7 +1089,6 @@ PPL::CO_Tree::move_data_from(CO_Tree& tree) {
void PPL::CO_Tree::copy_data_from(const CO_Tree& x) { - PPL_ASSERT(size_ == 0); PPL_ASSERT(reserved_size == x.reserved_size); PPL_ASSERT(structure_OK()); diff --git a/src/CO_Tree.defs.hh b/src/CO_Tree.defs.hh index 2c8a5ca..4254796 100644 --- a/src/CO_Tree.defs.hh +++ b/src/CO_Tree.defs.hh @@ -27,6 +27,7 @@ site: http://bugseng.com/products/ppl/ . */ #include "CO_Tree.types.hh"
#include "Coefficient.defs.hh" +#include <memory>
#ifndef PPL_CO_TREE_EXTRA_DEBUG #ifdef PPL_ABI_BREAKING_EXTRA_DEBUG @@ -1012,8 +1013,8 @@ private:
//! Compares the fractions numer/denom with ratio/100. /*! - \returns - Returns true if the fraction numer/denom is less than the fraction ratio/100. + \returns Returns true if the fraction numer/denom is less + than the fraction ratio/100.
\param ratio It must be less than or equal to 100. @@ -1279,6 +1280,9 @@ private: */ dimension_type* indexes;
+ //! The allocator used to allocate/deallocate data. + std::allocator<data_type> data_allocator; + //! The vector that contains the data of the keys in the tree. /*! If index[i] is \p unused_index, data[i] is unused. @@ -1299,8 +1303,6 @@ private:
//! The number of values stored in the tree. dimension_type size_; - - std::allocator<Coefficient> coefficient_allocator; };
class CO_Tree::tree_iterator { diff --git a/src/CO_Tree.inlines.hh b/src/CO_Tree.inlines.hh index 546817b..50a03e7 100644 --- a/src/CO_Tree.inlines.hh +++ b/src/CO_Tree.inlines.hh @@ -46,33 +46,26 @@ CO_Tree::dfs_index(iterator itr) const {
inline CO_Tree::CO_Tree() { - init(0); - PPL_ASSERT(OK()); }
inline CO_Tree::CO_Tree(const CO_Tree& x) { - PPL_ASSERT(x.OK()); - + data_allocator = x.data_allocator; init(x.reserved_size); - copy_data_from(x); }
inline CO_Tree& CO_Tree::operator=(const CO_Tree& x) { - if (this != &x) { - destroy(); + data_allocator = x.data_allocator; init(x.reserved_size); - copy_data_from(x); } - return *this; }
@@ -178,11 +171,12 @@ CO_Tree::m_swap(CO_Tree& x) { using std::swap; swap(max_depth, x.max_depth); swap(indexes, x.indexes); + swap(data_allocator, x.data_allocator); swap(data, x.data); swap(reserved_size, x.reserved_size); swap(size_, x.size_); - // Cached iterators have been invalidated by the swap, they must be - // refreshed here. + // Cached iterators have been invalidated by the swap, + // they must be refreshed here. refresh_cached_iterators(); x.refresh_cached_iterators(); PPL_ASSERT(structure_OK());
participants (1)
-
Enea Zaffanella