diff --git a/core/math/bvh.h b/core/math/bvh.h index 9a9dde17605..369c33674d1 100644 --- a/core/math/bvh.h +++ b/core/math/bvh.h @@ -769,7 +769,7 @@ private: // for collision pairing, // maintain a list of all items moved etc on each frame / tick - LocalVector changed_items; + LocalVector changed_items; uint32_t _tick = 1; // Start from 1 so items with 0 indicate never updated. class BVHLockedFunction { diff --git a/core/math/bvh_public.inc b/core/math/bvh_public.inc index fc1c67a21bb..f0a8edb08ae 100644 --- a/core/math/bvh_public.inc +++ b/core/math/bvh_public.inc @@ -202,7 +202,7 @@ void item_remove(BVHHandle p_handle) { // swap back and decrement for fast unordered remove _active_refs[active_ref_id] = ref_id_moved_back; - _active_refs.resize(_active_refs.size() - 1); + _active_refs.resize_uninitialized(_active_refs.size() - 1); // keep the moved active reference up to date _extra[ref_id_moved_back].active_ref_id = active_ref_id; diff --git a/core/math/bvh_structs.inc b/core/math/bvh_structs.inc index 6326cd63ef3..771fc13835d 100644 --- a/core/math/bvh_structs.inc +++ b/core/math/bvh_structs.inc @@ -172,13 +172,13 @@ PooledList _leaves; // we can maintain an un-ordered list of which references are active, // in order to do a slow incremental optimize of the tree over each frame. // This will work best if dynamic objects and static objects are in a different tree. -LocalVector _active_refs; +LocalVector _active_refs; uint32_t _current_active_ref = 0; // instead of translating directly to the userdata output, // we keep an intermediate list of hits as reference IDs, which can be used // for pairing collision detection -LocalVector _cull_hits; +LocalVector _cull_hits; // We can now have a user definable number of trees. // This allows using e.g. a non-pairable and pairable tree, diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index 2b8a1207599..50ad2cd0bb4 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -40,10 +40,10 @@ // If tight, it grows strictly as much as needed. // Otherwise, it grows exponentially (the default and what you want in most cases). -// force_trivial is used to avoid T's default value on resize, for improved performance. -// This requires T to be trivially destructible. template class LocalVector { + static_assert(!force_trivial, "force_trivial is no longer supported. Use resize_uninitialized instead."); + private: U count = 0; U capacity = 0; @@ -182,14 +182,13 @@ public: /// Resize the vector. /// Elements are initialized (or not) depending on what the default C++ behavior for T is. - /// Note: If force_trivial is set, this will behave like resize_trivial instead. + /// Note: If force_trivial is set, this will behave like resize_uninitialized instead. void resize(U p_size) { - // Don't init when trivially constructible, or force_trivial is set. - _resize>(p_size); + // Don't init when trivially constructible. + _resize>(p_size); } /// Resize and set all values to 0 / false / nullptr. - /// This is only available for zero constructible types. _FORCE_INLINE_ void resize_initialized(U p_size) { _resize(p_size); } /// Resize and set all values to 0 / false / nullptr. @@ -410,8 +409,8 @@ public: } }; -template -using TightLocalVector = LocalVector; +template +using TightLocalVector = LocalVector; // Zero-constructing LocalVector initializes count, capacity and data to 0 and thus empty. template diff --git a/core/templates/pooled_list.h b/core/templates/pooled_list.h index 4c7f3eda9ad..325bcad4e22 100644 --- a/core/templates/pooled_list.h +++ b/core/templates/pooled_list.h @@ -56,8 +56,8 @@ template class PooledList { - LocalVector list; - LocalVector freelist; + LocalVector list; + LocalVector freelist; // not all list members are necessarily used U _used_size; @@ -102,13 +102,17 @@ public: // pop from freelist int new_size = freelist.size() - 1; r_id = freelist[new_size]; - freelist.resize(new_size); + freelist.resize_uninitialized(new_size); return &list[r_id]; } r_id = list.size(); - list.resize(r_id + 1); + if constexpr (force_trivial || std::is_trivially_constructible_v) { + list.resize_uninitialized(r_id + 1); + } else { + list.resize_initialized(r_id + 1); + } static_assert((!zero_on_first_request) || (__is_pod(T)), "zero_on_first_request requires trivial type"); if constexpr (zero_on_first_request && __is_pod(T)) { @@ -169,7 +173,7 @@ public: // expand the active map (this should be in sync with the pool list if (_pool.used_size() > _active_map.size()) { - _active_map.resize(_pool.used_size()); + _active_map.resize_uninitialized(_pool.used_size()); } // store in the active map