summaryrefslogtreecommitdiffstats
path: root/core/templates
diff options
context:
space:
mode:
authorvittorioromeo <mail@vittorioromeo.com>2024-02-02 15:43:21 +0100
committervittorioromeo <mail@vittorioromeo.com>2024-02-02 15:43:21 +0100
commit55ed34e37c61ae53e676f73a2e4444d7ecb4ce7d (patch)
treea65f7e697634149faa5ff8f5b7edccbb32ba06bc /core/templates
parent10e111477db68fe65776a1d68fb1ffccaf6520fc (diff)
downloadredot-engine-55ed34e37c61ae53e676f73a2e4444d7ecb4ce7d.tar.gz
Use '_v' shorthand for type traits and 'if constexpr' where appropriate
Diffstat (limited to 'core/templates')
-rw-r--r--core/templates/cowdata.h8
-rw-r--r--core/templates/local_vector.h10
-rw-r--r--core/templates/paged_allocator.h2
-rw-r--r--core/templates/paged_array.h10
-rw-r--r--core/templates/safe_refcount.h2
5 files changed, 16 insertions, 16 deletions
diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h
index d43cf8107f..a0632b2645 100644
--- a/core/templates/cowdata.h
+++ b/core/templates/cowdata.h
@@ -233,7 +233,7 @@ void CowData<T>::_unref(void *p_data) {
}
// clean up
- if (!std::is_trivially_destructible<T>::value) {
+ if constexpr (!std::is_trivially_destructible_v<T>) {
USize *count = _get_size();
T *data = (T *)(count + 1);
@@ -269,7 +269,7 @@ typename CowData<T>::USize CowData<T>::_copy_on_write() {
T *_data = (T *)(mem_new);
// initialize new elements
- if (std::is_trivially_copyable<T>::value) {
+ if constexpr (std::is_trivially_copyable_v<T>) {
memcpy(mem_new, _ptr, current_size * sizeof(T));
} else {
@@ -335,7 +335,7 @@ Error CowData<T>::resize(Size p_size) {
// construct the newly created elements
- if (!std::is_trivially_constructible<T>::value) {
+ if constexpr (!std::is_trivially_constructible_v<T>) {
for (Size i = *_get_size(); i < p_size; i++) {
memnew_placement(&_ptr[i], T);
}
@@ -346,7 +346,7 @@ Error CowData<T>::resize(Size p_size) {
*_get_size() = p_size;
} else if (p_size < current_size) {
- if (!std::is_trivially_destructible<T>::value) {
+ if constexpr (!std::is_trivially_destructible_v<T>) {
// deinitialize no longer needed elements
for (USize i = p_size; i < *_get_size(); i++) {
T *t = &_ptr[i];
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h
index b454821a8f..17ddbf6161 100644
--- a/core/templates/local_vector.h
+++ b/core/templates/local_vector.h
@@ -64,7 +64,7 @@ public:
CRASH_COND_MSG(!data, "Out of memory");
}
- if constexpr (!std::is_trivially_constructible<T>::value && !force_trivial) {
+ if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) {
memnew_placement(&data[count++], T(p_elem));
} else {
data[count++] = p_elem;
@@ -77,7 +77,7 @@ public:
for (U i = p_index; i < count; i++) {
data[i] = data[i + 1];
}
- if constexpr (!std::is_trivially_destructible<T>::value && !force_trivial) {
+ if constexpr (!std::is_trivially_destructible_v<T> && !force_trivial) {
data[count].~T();
}
}
@@ -90,7 +90,7 @@ public:
if (count > p_index) {
data[p_index] = data[count];
}
- if constexpr (!std::is_trivially_destructible<T>::value && !force_trivial) {
+ if constexpr (!std::is_trivially_destructible_v<T> && !force_trivial) {
data[count].~T();
}
}
@@ -133,7 +133,7 @@ public:
_FORCE_INLINE_ U size() const { return count; }
void resize(U p_size) {
if (p_size < count) {
- if constexpr (!std::is_trivially_destructible<T>::value && !force_trivial) {
+ if constexpr (!std::is_trivially_destructible_v<T> && !force_trivial) {
for (U i = p_size; i < count; i++) {
data[i].~T();
}
@@ -145,7 +145,7 @@ public:
data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");
}
- if constexpr (!std::is_trivially_constructible<T>::value && !force_trivial) {
+ if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) {
for (U i = count; i < p_size; i++) {
memnew_placement(&data[i], T);
}
diff --git a/core/templates/paged_allocator.h b/core/templates/paged_allocator.h
index d880eae0c3..48110d37e5 100644
--- a/core/templates/paged_allocator.h
+++ b/core/templates/paged_allocator.h
@@ -101,7 +101,7 @@ public:
private:
void _reset(bool p_allow_unfreed) {
- if (!p_allow_unfreed || !std::is_trivially_destructible<T>::value) {
+ if (!p_allow_unfreed || !std::is_trivially_destructible_v<T>) {
ERR_FAIL_COND(allocs_available < pages_allocated * page_size);
}
if (pages_allocated) {
diff --git a/core/templates/paged_array.h b/core/templates/paged_array.h
index 6b7e0cee16..21053dd033 100644
--- a/core/templates/paged_array.h
+++ b/core/templates/paged_array.h
@@ -202,7 +202,7 @@ public:
uint32_t page = count >> page_size_shift;
uint32_t offset = count & page_size_mask;
- if (!std::is_trivially_constructible<T>::value) {
+ if constexpr (!std::is_trivially_constructible_v<T>) {
memnew_placement(&page_data[page][offset], T(p_value));
} else {
page_data[page][offset] = p_value;
@@ -214,7 +214,7 @@ public:
_FORCE_INLINE_ void pop_back() {
ERR_FAIL_COND(count == 0);
- if (!std::is_trivially_destructible<T>::value) {
+ if constexpr (!std::is_trivially_destructible_v<T>) {
uint32_t page = (count - 1) >> page_size_shift;
uint32_t offset = (count - 1) & page_size_mask;
page_data[page][offset].~T();
@@ -237,7 +237,7 @@ public:
void clear() {
//destruct if needed
- if (!std::is_trivially_destructible<T>::value) {
+ if constexpr (!std::is_trivially_destructible_v<T>) {
for (uint64_t i = 0; i < count; i++) {
uint32_t page = i >> page_size_shift;
uint32_t offset = i & page_size_mask;
@@ -318,13 +318,13 @@ public:
uint32_t to_copy = MIN(page_size - new_remainder, remainder);
for (uint32_t i = 0; i < to_copy; i++) {
- if (!std::is_trivially_constructible<T>::value) {
+ if constexpr (!std::is_trivially_constructible_v<T>) {
memnew_placement(&dst_page[i + new_remainder], T(remainder_page[i + remainder - to_copy]));
} else {
dst_page[i + new_remainder] = remainder_page[i + remainder - to_copy];
}
- if (!std::is_trivially_destructible<T>::value) {
+ if constexpr (!std::is_trivially_destructible_v<T>) {
remainder_page[i + remainder - to_copy].~T();
}
}
diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h
index 20fb0c6501..7bbceadc8d 100644
--- a/core/templates/safe_refcount.h
+++ b/core/templates/safe_refcount.h
@@ -54,7 +54,7 @@
#define SAFE_NUMERIC_TYPE_PUN_GUARANTEES(m_type) \
static_assert(sizeof(SafeNumeric<m_type>) == sizeof(m_type)); \
static_assert(alignof(SafeNumeric<m_type>) == alignof(m_type)); \
- static_assert(std::is_trivially_destructible<std::atomic<m_type>>::value);
+ static_assert(std::is_trivially_destructible_v<std::atomic<m_type>>);
#define SAFE_FLAG_TYPE_PUN_GUARANTEES \
static_assert(sizeof(SafeFlag) == sizeof(bool)); \
static_assert(alignof(SafeFlag) == alignof(bool));