Skip to content

Commit 2cde929

Browse files
committed
Merge pull request #106876 from Ivorforce/localvector-no-force-trivial
Un-support `force_trivial` parameter for `LocalVector`. Instead, users should use `resize_uninitialized`.
2 parents 4e000e2 + 3741553 commit 2cde929

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

core/math/bvh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ class BVH_Manager {
769769

770770
// for collision pairing,
771771
// maintain a list of all items moved etc on each frame / tick
772-
LocalVector<BVHHandle, uint32_t, true> changed_items;
772+
LocalVector<BVHHandle> changed_items;
773773
uint32_t _tick = 1; // Start from 1 so items with 0 indicate never updated.
774774

775775
class BVHLockedFunction {

core/math/bvh_public.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void item_remove(BVHHandle p_handle) {
202202

203203
// swap back and decrement for fast unordered remove
204204
_active_refs[active_ref_id] = ref_id_moved_back;
205-
_active_refs.resize(_active_refs.size() - 1);
205+
_active_refs.resize_uninitialized(_active_refs.size() - 1);
206206

207207
// keep the moved active reference up to date
208208
_extra[ref_id_moved_back].active_ref_id = active_ref_id;

core/math/bvh_structs.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ PooledList<TLeaf, uint32_t, true> _leaves;
172172
// we can maintain an un-ordered list of which references are active,
173173
// in order to do a slow incremental optimize of the tree over each frame.
174174
// This will work best if dynamic objects and static objects are in a different tree.
175-
LocalVector<uint32_t, uint32_t, true> _active_refs;
175+
LocalVector<uint32_t> _active_refs;
176176
uint32_t _current_active_ref = 0;
177177

178178
// instead of translating directly to the userdata output,
179179
// we keep an intermediate list of hits as reference IDs, which can be used
180180
// for pairing collision detection
181-
LocalVector<uint32_t, uint32_t, true> _cull_hits;
181+
LocalVector<uint32_t> _cull_hits;
182182

183183
// We can now have a user definable number of trees.
184184
// This allows using e.g. a non-pairable and pairable tree,

core/templates/local_vector.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040

4141
// If tight, it grows strictly as much as needed.
4242
// Otherwise, it grows exponentially (the default and what you want in most cases).
43-
// force_trivial is used to avoid T's default value on resize, for improved performance.
44-
// This requires T to be trivially destructible.
4543
template <typename T, typename U = uint32_t, bool force_trivial = false, bool tight = false>
4644
class LocalVector {
45+
static_assert(!force_trivial, "force_trivial is no longer supported. Use resize_uninitialized instead.");
46+
4747
private:
4848
U count = 0;
4949
U capacity = 0;
@@ -182,14 +182,13 @@ class LocalVector {
182182

183183
/// Resize the vector.
184184
/// Elements are initialized (or not) depending on what the default C++ behavior for T is.
185-
/// Note: If force_trivial is set, this will behave like resize_trivial instead.
185+
/// Note: If force_trivial is set, this will behave like resize_uninitialized instead.
186186
void resize(U p_size) {
187-
// Don't init when trivially constructible, or force_trivial is set.
188-
_resize<!force_trivial && !std::is_trivially_constructible_v<T>>(p_size);
187+
// Don't init when trivially constructible.
188+
_resize<!std::is_trivially_constructible_v<T>>(p_size);
189189
}
190190

191191
/// Resize and set all values to 0 / false / nullptr.
192-
/// This is only available for zero constructible types.
193192
_FORCE_INLINE_ void resize_initialized(U p_size) { _resize<true>(p_size); }
194193

195194
/// Resize and set all values to 0 / false / nullptr.
@@ -410,8 +409,8 @@ class LocalVector {
410409
}
411410
};
412411

413-
template <typename T, typename U = uint32_t, bool force_trivial = false>
414-
using TightLocalVector = LocalVector<T, U, force_trivial, true>;
412+
template <typename T, typename U = uint32_t>
413+
using TightLocalVector = LocalVector<T, U, false, true>;
415414

416415
// Zero-constructing LocalVector initializes count, capacity and data to 0 and thus empty.
417416
template <typename T, typename U, bool force_trivial, bool tight>

core/templates/pooled_list.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656

5757
template <typename T, typename U = uint32_t, bool force_trivial = false, bool zero_on_first_request = false>
5858
class PooledList {
59-
LocalVector<T, U, force_trivial> list;
60-
LocalVector<U, U, true> freelist;
59+
LocalVector<T, U> list;
60+
LocalVector<U, U> freelist;
6161

6262
// not all list members are necessarily used
6363
U _used_size;
@@ -102,13 +102,17 @@ class PooledList {
102102
// pop from freelist
103103
int new_size = freelist.size() - 1;
104104
r_id = freelist[new_size];
105-
freelist.resize(new_size);
105+
freelist.resize_uninitialized(new_size);
106106

107107
return &list[r_id];
108108
}
109109

110110
r_id = list.size();
111-
list.resize(r_id + 1);
111+
if constexpr (force_trivial || std::is_trivially_constructible_v<T>) {
112+
list.resize_uninitialized(r_id + 1);
113+
} else {
114+
list.resize_initialized(r_id + 1);
115+
}
112116

113117
static_assert((!zero_on_first_request) || (__is_pod(T)), "zero_on_first_request requires trivial type");
114118
if constexpr (zero_on_first_request && __is_pod(T)) {
@@ -169,7 +173,7 @@ class TrackedPooledList {
169173

170174
// expand the active map (this should be in sync with the pool list
171175
if (_pool.used_size() > _active_map.size()) {
172-
_active_map.resize(_pool.used_size());
176+
_active_map.resize_uninitialized(_pool.used_size());
173177
}
174178

175179
// store in the active map

0 commit comments

Comments
 (0)