diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h index 5a4f823e669..810142879dd 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h @@ -236,7 +236,7 @@ class Property_container public: // default constructor - Property_container() : size_(0) {} + Property_container() : size_(0), capacity_(0) {} // destructor (deletes all property arrays) virtual ~Property_container() { clear(); } @@ -252,6 +252,7 @@ public: clear(); parrays_.resize(_rhs.n_properties()); size_ = _rhs.size(); + capacity_ = _rhs.capacity(); for (std::size_t i=0; iclone(); } @@ -287,6 +288,7 @@ public: continue; parrays_.push_back (_rhs.parrays_[i]->empty_clone()); + parrays_.back()->reserve(capacity_); parrays_.back()->resize(size_); } } @@ -305,6 +307,9 @@ public: // returns the current size of the property arrays size_t size() const { return size_; } + // returns the current capacity of the property arrays + size_t capacity() const { return capacity_; } + // returns the number of property arrays size_t n_properties() const { return parrays_.size(); } @@ -353,6 +358,7 @@ public: // otherwise add the property Property_array* p = new Property_array(name, t); + p->reserve(capacity_); p->resize(size_); parrays_.push_back(p); return std::make_pair(Pmap(p), true); @@ -430,10 +436,11 @@ public: // reserve memory for n entries in all arrays - void reserve(size_t n) const + void reserve(size_t n) { for (std::size_t i=0; ireserve(n); + capacity_ = std::max(n, capacity_); } // resize all arrays to size n @@ -445,10 +452,11 @@ public: } // free unused space in all arrays - void shrink_to_fit() const + void shrink_to_fit() { for (std::size_t i=0; ishrink_to_fit(); + capacity_ = size_; } // add a new element to each vector @@ -457,6 +465,7 @@ public: for (std::size_t i=0; ipush_back(); ++size_; + capacity_ = (std::max(size_, capacity_)); } // reset element to its default property values @@ -483,6 +492,7 @@ public: private: std::vector parrays_; size_t size_; + size_t capacity_; }; /// @endcond