[Bf-blender-cvs] [f204ea5624c] functions: Fix append_n_time reallocating every time
Jacques Lucke
noreply at git.blender.org
Sat Jul 6 17:30:24 CEST 2019
Commit: f204ea5624cb5b98aa464d9e5dfc9a4298e59e3e
Author: Jacques Lucke
Date: Sat Jul 6 15:14:51 2019 +0200
Branches: functions
https://developer.blender.org/rBf204ea5624cb5b98aa464d9e5dfc9a4298e59e3e
Fix append_n_time reallocating every time
===================================================================
M source/blender/blenlib/BLI_small_vector.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_small_vector.hpp b/source/blender/blenlib/BLI_small_vector.hpp
index 9585936cf89..cd76a5bf031 100644
--- a/source/blender/blenlib/BLI_small_vector.hpp
+++ b/source/blender/blenlib/BLI_small_vector.hpp
@@ -35,6 +35,7 @@
#include "BLI_utildefines.h"
#include "BLI_array_ref.hpp"
#include "BLI_listbase_wrapper.hpp"
+#include "BLI_math_base.h"
#include "MEM_guardedalloc.h"
@@ -435,6 +436,10 @@ template<typename T, uint N = 4> class SmallVector {
return;
}
+ /* Round up to the next power of two. Otherwise consecutive calls to grow can cause a
+ * reallocation every time even though the min_capacity only increments. */
+ min_capacity = power_of_2_max_u(min_capacity);
+
m_capacity = min_capacity;
T *new_array = (T *)MEM_malloc_arrayN(m_capacity, sizeof(T), __func__);
More information about the Bf-blender-cvs
mailing list