Skip to content

Commit 165415b

Browse files
author
Julian LALU
committed
Improve hud::memory
1 parent 01ed542 commit 165415b

File tree

17 files changed

+418
-148
lines changed

17 files changed

+418
-148
lines changed

interface/core/containers/array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ namespace hud
291291
// This optimization works only if allocator do not share the same memory allocation, this case is not used in the engine
292292
if (!hud::is_constant_evaluated() && hud::is_bitwise_copy_constructible_v<type_t, u_type_t> && hud::is_bitwise_move_constructible_v<type_t, u_type_t>)
293293
{
294-
hud::memory::copy(data(), other.data(), byte_count());
294+
hud::memory::copy_memory(data(), other.data(), byte_count());
295295
}
296296
else
297297
{
@@ -319,7 +319,7 @@ namespace hud
319319
// This optimization works only if allocator do not share the same memory buffer, this case is not used in the engine
320320
if (!hud::is_constant_evaluated() && hud::is_bitwise_copy_constructible_v<type_t, u_type_t> && hud::is_bitwise_move_constructible_v<type_t, u_type_t>)
321321
{
322-
hud::memory::copy(data(), other.data(), byte_count());
322+
hud::memory::copy_memory(data(), other.data(), byte_count());
323323
}
324324
else
325325
{

interface/core/containers/hashset.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ namespace hud
176176
}
177177

178178
[[nodiscard]]
179-
friend constexpr bool operator==(const mask &a, const mask &b)
179+
friend constexpr bool operator==(const mask &a, const mask &b) noexcept
180180
{
181181
return a.mask_value_ == b.mask_value_;
182182
}
183183

184184
[[nodiscard]]
185-
friend constexpr bool operator!=(const mask &a, const mask &b)
185+
friend constexpr bool operator!=(const mask &a, const mask &b) noexcept
186186
{
187187
return !(a == b);
188188
}
@@ -612,7 +612,7 @@ namespace hud
612612
if (hud::is_constant_evaluated() || !hud::is_bitwise_copy_constructible_v<slot_type>)
613613
{
614614
// Set control to empty ending with sentinel
615-
hud::memory::set(control_ptr_, control_size, empty_byte);
615+
hud::memory::set_memory(control_ptr_, control_size, empty_byte);
616616
control_ptr_[max_slot_count_] = sentinel_byte;
617617

618618
// Copy slots to newly allocated buffer
@@ -665,7 +665,7 @@ namespace hud
665665
if (extra_max_count > 0 || hud::is_constant_evaluated() || !hud::is_bitwise_copy_constructible_v<slot_type>)
666666
{
667667
// Set control to empty ending with sentinel
668-
hud::memory::set(control_ptr_, control_size, empty_byte);
668+
hud::memory::set_memory(control_ptr_, control_size, empty_byte);
669669
control_ptr_[max_slot_count_] = sentinel_byte;
670670

671671
// Copy slots to newly allocated buffer
@@ -978,7 +978,7 @@ namespace hud
978978
free_slot_before_grow_ = max_slot_before_grow(max_slot_count_) - count_;
979979

980980
// Set control to empty ending with sentinel
981-
hud::memory::set(control_ptr_, control_size, empty_byte);
981+
hud::memory::set_memory(control_ptr_, control_size, empty_byte);
982982
control_ptr_[max_slot_count_] = sentinel_byte;
983983

984984
// If we have elements, insert them to the new buffer

interface/core/memory/memory.h

Lines changed: 293 additions & 70 deletions
Large diffs are not rendered by default.

interface/core/uuid/uuid_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace hud::common
5959
/** Reset the uuid with all components to zero. Making it invalid*/
6060
void reset() noexcept
6161
{
62-
hud::memory::set_zero(this, sizeof(uuid));
62+
hud::memory::set_memory_zero(this, sizeof(uuid));
6363
}
6464

6565
/**
@@ -69,7 +69,7 @@ namespace hud::common
6969
*/
7070
uuid &operator=(const uuid &other) noexcept
7171
{
72-
hud::memory::copy(this, &other, sizeof(uuid));
72+
hud::memory::copy_memory(this, &other, sizeof(uuid));
7373
return *this;
7474
}
7575

test/allocator/allocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ GTEST_TEST(memory_allocation, range_for_loop)
330330

331331
const hud::memory_allocation<i32> &slice_const = slice;
332332
index = 0;
333-
hud::memory::set_zero(result);
333+
hud::memory::set_memory_zero_safe(result);
334334

335335
// constexpr ConstIterator begin() const noexcept
336336
// constexpr ConstIterator end() const noexcept

test/array/array_assignment.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,9 +1900,9 @@ GTEST_TEST(array, assign_std_initializer_list_call_destructor_of_elements)
19001900
if (count_in_assigned > 0)
19011901
{
19021902
dtor_assigned_counter = hud::memory::allocate_array<i32>(count_in_assigned);
1903-
hud::memory::set_zero(dtor_assigned_counter, count_in_assigned * sizeof(i32));
1903+
hud::memory::set_memory_zero_safe(dtor_assigned_counter, count_in_assigned * sizeof(i32));
19041904
dtor_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_in_assigned);
1905-
hud::memory::set_zero(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
1905+
hud::memory::set_memory_zero_safe(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
19061906
for (usize index = 0; index < count_in_assigned; index++)
19071907
{
19081908
dtor_assigned_ptr_counter[index] = dtor_assigned_counter + index;
@@ -1917,9 +1917,9 @@ GTEST_TEST(array, assign_std_initializer_list_call_destructor_of_elements)
19171917
if (count_to_assigned > 0)
19181918
{
19191919
dtor_to_assigned_counter = hud::memory::allocate_array<i32>(count_to_assigned);
1920-
hud::memory::set_zero(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
1920+
hud::memory::set_memory_zero_safe(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
19211921
dtor_to_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_to_assigned);
1922-
hud::memory::set_zero(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
1922+
hud::memory::set_memory_zero_safe(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
19231923
for (usize index = 0; index < count_to_assigned; index++)
19241924
{
19251925
dtor_to_assigned_ptr_counter[index] = dtor_to_assigned_counter + index;
@@ -2116,9 +2116,9 @@ GTEST_TEST(array, assign_std_initializer_list_call_destructor_of_elements)
21162116
if (count_in_assigned > 0)
21172117
{
21182118
dtor_assigned_counter = hud::memory::allocate_array<i32>(count_in_assigned);
2119-
hud::memory::set_zero(dtor_assigned_counter, count_in_assigned * sizeof(i32));
2119+
hud::memory::set_memory_zero_safe(dtor_assigned_counter, count_in_assigned * sizeof(i32));
21202120
dtor_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_in_assigned);
2121-
hud::memory::set_zero(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
2121+
hud::memory::set_memory_zero_safe(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
21222122
for (usize index = 0; index < count_in_assigned; index++)
21232123
{
21242124
dtor_assigned_ptr_counter[index] = dtor_assigned_counter + index;
@@ -2133,9 +2133,9 @@ GTEST_TEST(array, assign_std_initializer_list_call_destructor_of_elements)
21332133
if (count_to_assigned > 0)
21342134
{
21352135
dtor_to_assigned_counter = hud::memory::allocate_array<i32>(count_to_assigned);
2136-
hud::memory::set_zero(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
2136+
hud::memory::set_memory_zero_safe(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
21372137
dtor_to_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_to_assigned);
2138-
hud::memory::set_zero(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
2138+
hud::memory::set_memory_zero_safe(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
21392139
for (usize index = 0; index < count_to_assigned; index++)
21402140
{
21412141
dtor_to_assigned_ptr_counter[index] = dtor_to_assigned_counter + index;

test/array/array_copy_assign_operator.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5717,9 +5717,9 @@ GTEST_TEST(array, copy_assign_array_same_allocator_call_destructor_of_elements)
57175717
if (count_in_assigned > 0)
57185718
{
57195719
dtor_assigned_counter = hud::memory::allocate_array<i32>(count_in_assigned);
5720-
hud::memory::set_zero(dtor_assigned_counter, count_in_assigned * sizeof(i32));
5720+
hud::memory::set_memory_zero_safe(dtor_assigned_counter, count_in_assigned * sizeof(i32));
57215721
dtor_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_in_assigned);
5722-
hud::memory::set_zero(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
5722+
hud::memory::set_memory_zero_safe(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
57235723
for (usize index = 0; index < count_in_assigned; index++)
57245724
{
57255725
dtor_assigned_ptr_counter[index] = dtor_assigned_counter + index;
@@ -5734,9 +5734,9 @@ GTEST_TEST(array, copy_assign_array_same_allocator_call_destructor_of_elements)
57345734
if (count_to_assigned > 0)
57355735
{
57365736
dtor_to_assigned_counter = hud::memory::allocate_array<i32>(count_to_assigned);
5737-
hud::memory::set_zero(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
5737+
hud::memory::set_memory_zero_safe(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
57385738
dtor_to_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_to_assigned);
5739-
hud::memory::set_zero(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
5739+
hud::memory::set_memory_zero_safe(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
57405740
for (usize index = 0; index < count_to_assigned; index++)
57415741
{
57425742
dtor_to_assigned_ptr_counter[index] = dtor_to_assigned_counter + index;
@@ -5924,9 +5924,9 @@ GTEST_TEST(array, copy_assign_array_same_allocator_call_destructor_of_elements)
59245924
if (count_in_assigned > 0)
59255925
{
59265926
dtor_assigned_counter = hud::memory::allocate_array<i32>(count_in_assigned);
5927-
hud::memory::set_zero(dtor_assigned_counter, count_in_assigned * sizeof(i32));
5927+
hud::memory::set_memory_zero_safe(dtor_assigned_counter, count_in_assigned * sizeof(i32));
59285928
dtor_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_in_assigned);
5929-
hud::memory::set_zero(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
5929+
hud::memory::set_memory_zero_safe(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
59305930
for (usize index = 0; index < count_in_assigned; index++)
59315931
{
59325932
dtor_assigned_ptr_counter[index] = dtor_assigned_counter + index;
@@ -5941,9 +5941,9 @@ GTEST_TEST(array, copy_assign_array_same_allocator_call_destructor_of_elements)
59415941
if (count_to_assign > 0)
59425942
{
59435943
dtor_to_assigned_counter = hud::memory::allocate_array<i32>(count_to_assign);
5944-
hud::memory::set_zero(dtor_to_assigned_counter, count_to_assign * sizeof(i32));
5944+
hud::memory::set_memory_zero_safe(dtor_to_assigned_counter, count_to_assign * sizeof(i32));
59455945
dtor_to_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_to_assign);
5946-
hud::memory::set_zero(dtor_to_assigned_ptr_counter, count_to_assign * sizeof(i32 *));
5946+
hud::memory::set_memory_zero_safe(dtor_to_assigned_ptr_counter, count_to_assign * sizeof(i32 *));
59475947
for (usize index = 0; index < count_to_assign; index++)
59485948
{
59495949
dtor_to_assigned_ptr_counter[index] = dtor_to_assigned_counter + index;
@@ -6397,9 +6397,9 @@ GTEST_TEST(array, copy_assign_array_different_allocator_call_destructor_of_eleme
63976397
if (count_in_assigned > 0)
63986398
{
63996399
dtor_assigned_counter = hud::memory::allocate_array<i32>(count_in_assigned);
6400-
hud::memory::set_zero(dtor_assigned_counter, count_in_assigned * sizeof(i32));
6400+
hud::memory::set_memory_zero_safe(dtor_assigned_counter, count_in_assigned * sizeof(i32));
64016401
dtor_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_in_assigned);
6402-
hud::memory::set_zero(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
6402+
hud::memory::set_memory_zero_safe(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
64036403
for (usize index = 0; index < count_in_assigned; index++)
64046404
{
64056405
dtor_assigned_ptr_counter[index] = dtor_assigned_counter + index;
@@ -6414,9 +6414,9 @@ GTEST_TEST(array, copy_assign_array_different_allocator_call_destructor_of_eleme
64146414
if (count_to_assigned > 0)
64156415
{
64166416
dtor_to_assigned_counter = hud::memory::allocate_array<i32>(count_to_assigned);
6417-
hud::memory::set_zero(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
6417+
hud::memory::set_memory_zero_safe(dtor_to_assigned_counter, count_to_assigned * sizeof(i32));
64186418
dtor_to_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_to_assigned);
6419-
hud::memory::set_zero(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
6419+
hud::memory::set_memory_zero_safe(dtor_to_assigned_ptr_counter, count_to_assigned * sizeof(i32 *));
64206420
for (usize index = 0; index < count_to_assigned; index++)
64216421
{
64226422
dtor_to_assigned_ptr_counter[index] = dtor_to_assigned_counter + index;
@@ -6604,9 +6604,9 @@ GTEST_TEST(array, copy_assign_array_different_allocator_call_destructor_of_eleme
66046604
if (count_in_assigned > 0)
66056605
{
66066606
dtor_assigned_counter = hud::memory::allocate_array<i32>(count_in_assigned);
6607-
hud::memory::set_zero(dtor_assigned_counter, count_in_assigned * sizeof(i32));
6607+
hud::memory::set_memory_zero_safe(dtor_assigned_counter, count_in_assigned * sizeof(i32));
66086608
dtor_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_in_assigned);
6609-
hud::memory::set_zero(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
6609+
hud::memory::set_memory_zero_safe(dtor_assigned_ptr_counter, count_in_assigned * sizeof(i32 *));
66106610
for (usize index = 0; index < count_in_assigned; index++)
66116611
{
66126612
dtor_assigned_ptr_counter[index] = dtor_assigned_counter + index;
@@ -6621,9 +6621,9 @@ GTEST_TEST(array, copy_assign_array_different_allocator_call_destructor_of_eleme
66216621
if (count_to_assign > 0)
66226622
{
66236623
dtor_to_assigned_counter = hud::memory::allocate_array<i32>(count_to_assign);
6624-
hud::memory::set_zero(dtor_to_assigned_counter, count_to_assign * sizeof(i32));
6624+
hud::memory::set_memory_zero_safe(dtor_to_assigned_counter, count_to_assign * sizeof(i32));
66256625
dtor_to_assigned_ptr_counter = hud::memory::allocate_array<i32 *>(count_to_assign);
6626-
hud::memory::set_zero(dtor_to_assigned_ptr_counter, count_to_assign * sizeof(i32 *));
6626+
hud::memory::set_memory_zero_safe(dtor_to_assigned_ptr_counter, count_to_assign * sizeof(i32 *));
66276627
for (usize index = 0; index < count_to_assign; index++)
66286628
{
66296629
dtor_to_assigned_ptr_counter[index] = dtor_to_assigned_counter + index;

test/array/array_destructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ GTEST_TEST(array, destructor_call_elements_destructors)
1010
auto test_destructor = []()
1111
{
1212
i32 dtor_order[2];
13-
hud::memory::set_zero(dtor_order);
13+
hud::memory::set_memory_zero_safe(dtor_order);
1414
i32 *dtor_order_ptr[2] = {&dtor_order[0], &dtor_order[1]};
1515

1616
bool all_destructor_are_not_called = true;
@@ -68,7 +68,7 @@ GTEST_TEST(array, destructor_call_elements_destructors)
6868
auto test_destructor = []()
6969
{
7070
i32 dtor_order[2];
71-
hud::memory::set_zero(dtor_order);
71+
hud::memory::set_memory_zero_safe(dtor_order);
7272
i32 *dtor_order_ptr[2] = {&dtor_order[0], &dtor_order[1]};
7373

7474
bool all_destructor_are_not_called = true;

0 commit comments

Comments
 (0)