mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Un-support force_trivial parameter for LocalVector. Instead, users are reformatted to use resize_uninitialized to make it explicit that the resize does not initialize missing elements.
This commit is contained in:
@@ -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 <typename T, typename U = uint32_t, bool force_trivial = false, bool tight = false>
|
||||
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<!force_trivial && !std::is_trivially_constructible_v<T>>(p_size);
|
||||
// Don't init when trivially constructible.
|
||||
_resize<!std::is_trivially_constructible_v<T>>(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<true>(p_size); }
|
||||
|
||||
/// Resize and set all values to 0 / false / nullptr.
|
||||
@@ -410,8 +409,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename U = uint32_t, bool force_trivial = false>
|
||||
using TightLocalVector = LocalVector<T, U, force_trivial, true>;
|
||||
template <typename T, typename U = uint32_t>
|
||||
using TightLocalVector = LocalVector<T, U, false, true>;
|
||||
|
||||
// Zero-constructing LocalVector initializes count, capacity and data to 0 and thus empty.
|
||||
template <typename T, typename U, bool force_trivial, bool tight>
|
||||
|
||||
@@ -56,8 +56,8 @@
|
||||
|
||||
template <typename T, typename U = uint32_t, bool force_trivial = false, bool zero_on_first_request = false>
|
||||
class PooledList {
|
||||
LocalVector<T, U, force_trivial> list;
|
||||
LocalVector<U, U, true> freelist;
|
||||
LocalVector<T, U> list;
|
||||
LocalVector<U, U> 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<T>) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user