From a5e1c6e3c6b4110a6d56c951ffceaa0ebc1a5a75 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Tue, 28 Jan 2020 10:58:36 +0100 Subject: [PATCH 1/3] Fix capacity handling in properties --- Surface_mesh/include/CGAL/Surface_mesh/Properties.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h index 98d4f69184c..0eda3d86e34 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h @@ -245,7 +245,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(); } @@ -261,6 +261,7 @@ public: clear(); parrays_.resize(_rhs.n_properties()); size_ = _rhs.size(); + capacity_ = _rhs.capacity(); for (std::size_t i=0; iclone(); } @@ -296,6 +297,7 @@ public: continue; parrays_.push_back (_rhs.parrays_[i]->empty_clone()); + parrays_.back()->reserve(capacity_); parrays_.back()->resize(size_); } } @@ -314,6 +316,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(); } @@ -362,6 +367,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); @@ -443,6 +449,7 @@ public: { for (std::size_t i=0; ireserve(n); + capacity_ = n; } // resize all arrays to size n @@ -458,6 +465,7 @@ public: { for (std::size_t i=0; ishrink_to_fit(); + capacity_ = size_; } // add a new element to each vector @@ -466,6 +474,7 @@ public: for (std::size_t i=0; ipush_back(); ++size_; + capacity_ = (std::max(size_, capacity_)); } // reset element to its default property values @@ -491,6 +500,7 @@ public: private: std::vector parrays_; size_t size_; + mutable size_t capacity_; }; /// @endcond From bf12b38c2b02eb8dd77811342126d9bfa3565f9a Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Tue, 28 Jan 2020 11:14:10 +0100 Subject: [PATCH 2/3] Fix constness w.r.t capacity --- Surface_mesh/include/CGAL/Surface_mesh/Properties.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h index 0eda3d86e34..2a069522503 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h @@ -445,7 +445,7 @@ 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); @@ -461,7 +461,7 @@ 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(); @@ -500,7 +500,7 @@ public: private: std::vector parrays_; size_t size_; - mutable size_t capacity_; + size_t capacity_; }; /// @endcond From 283a264f5eb9ced4ee8b19476d7b6d3e2619ba93 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Tue, 28 Jan 2020 11:14:53 +0100 Subject: [PATCH 3/3] Fix reserve (update capacity only if bigger) --- Surface_mesh/include/CGAL/Surface_mesh/Properties.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h index 2a069522503..0e7ab8712ff 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h @@ -449,7 +449,7 @@ public: { for (std::size_t i=0; ireserve(n); - capacity_ = n; + capacity_ = std::max(n, capacity_); } // resize all arrays to size n