[Bf-blender-cvs] [1acb1b8cbd7] temp-T97352-3d-texturing-seam-bleeding-b2: Added VectorList from D13289.
Jeroen Bakker
noreply at git.blender.org
Thu Jul 7 10:32:35 CEST 2022
Commit: 1acb1b8cbd7d71b5b39be2b53c72358f97de7ef5
Author: Jeroen Bakker
Date: Thu Jul 7 10:32:39 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rB1acb1b8cbd7d71b5b39be2b53c72358f97de7ef5
Added VectorList from D13289.
===================================================================
A source/blender/blenlib/BLI_vector_list.hh
M source/blender/blenlib/CMakeLists.txt
===================================================================
diff --git a/source/blender/blenlib/BLI_vector_list.hh b/source/blender/blenlib/BLI_vector_list.hh
new file mode 100644
index 00000000000..177b2ef91d0
--- /dev/null
+++ b/source/blender/blenlib/BLI_vector_list.hh
@@ -0,0 +1,105 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <algorithm>
+
+#include "BLI_vector.hh"
+
+namespace blender {
+
+template<typename T> class VectorList {
+ private:
+ using UsedVector = Vector<T, 0>;
+ static constexpr int64_t vector_capacity_start = 32;
+ static constexpr int64_t vector_capacity_soft_limit = 4096;
+
+ /**
+ * Contains the individual vectors. There must always be at least one vector.
+ */
+ Vector<UsedVector> vectors_;
+
+ public:
+ VectorList()
+ {
+ this->append_vector();
+ }
+
+ void append(const T &value)
+ {
+ this->append_as(value);
+ }
+
+ void append(T &&value)
+ {
+ this->append_as(std::move(value));
+ }
+
+ template<typename ForwardT> void append_as(ForwardT &&value)
+ {
+ UsedVector &vector = this->ensure_space_for_one();
+ vector.append_unchecked_as(std::forward<ForwardT>(value));
+ }
+
+ UsedVector *begin()
+ {
+ return vectors_.begin();
+ }
+
+ UsedVector *end()
+ {
+ return vectors_.end();
+ }
+
+ const UsedVector *begin() const
+ {
+ return vectors_.begin();
+ }
+
+ const UsedVector *end() const
+ {
+ return vectors_.end();
+ }
+
+ private:
+ UsedVector &ensure_space_for_one()
+ {
+ UsedVector &vector = vectors_.last();
+ if (LIKELY(!vector.is_at_capacity())) {
+ return vector;
+ }
+ this->append_vector();
+ return vectors_.last();
+ }
+
+ void append_vector()
+ {
+ const int64_t new_vector_capacity = this->get_next_vector_capacity();
+ vectors_.append({});
+ vectors_.last().reserve(new_vector_capacity);
+ }
+
+ int64_t get_next_vector_capacity()
+ {
+ if (vectors_.is_empty()) {
+ return vector_capacity_start;
+ }
+ return std::min(vectors_.last().capacity() * 2, vector_capacity_soft_limit);
+ }
+};
+
+} // namespace blender
\ No newline at end of file
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 95b4987596e..a879045781b 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -324,6 +324,7 @@ set(SRC
BLI_uvproject.h
BLI_vector.hh
BLI_vector_adaptor.hh
+ BLI_vector_list.hh
BLI_vector_set.hh
BLI_vector_set_slots.hh
BLI_virtual_array.hh
More information about the Bf-blender-cvs
mailing list