@@ -1725,8 +1725,7 @@ namespace hud
17251725 max_slot_count_ = new_max_slot_count;
17261726
17271727 // Allocate the buffer that will contain controls and aligned slots
1728- // In a constant-evaluated context, bit_cast cannot be used with pointers
1729- // To satisfy the compiler, allocate controls and slots in two separate allocations
1728+ // In a constant-evaluated context, to satisfy the compiler, allocate controls and slots in two separate allocations
17301729 usize control_size {allocate_control_and_slot (max_slot_count_)};
17311730
17321731 // Update number of slot we should put into the table before a resizing rehash
@@ -1888,25 +1887,21 @@ namespace hud
18881887 * | controls | slot padding | slots |
18891888 * ^ ^
18901889 * control_ptr_ slot_ptr_
1891- *
18921890 */
1893-
18941891 const usize control_size {control_size_for_max_count (max_slot_count)};
18951892 const usize slots_size {max_slot_count * sizeof (slot_type)};
1896- const uptr aligned_control_size {hud::memory::align_address (control_size, sizeof (slot_type))};
18971893
18981894 if (hud::is_constant_evaluated ())
18991895 {
1900- control_ptr_ = allocator_.template allocate <control_type>(aligned_control_size ).data ();
1896+ control_ptr_ = allocator_.template allocate <control_type>(control_size ).data ();
19011897 slot_ptr_ = allocator_.template allocate <slot_type>(slots_size).data ();
19021898 }
19031899 else
19041900 {
1905-
1906- const usize aligned_allocation_size {aligned_control_size + slots_size};
1901+ // Allocate control, slot, and slot size to satisfy slot_ptr_ alignment requirements
1902+ const usize aligned_allocation_size {control_size + sizeof (slot_type) + slots_size};
19071903 control_ptr_ = allocator_.template allocate <control_type>(aligned_allocation_size).data ();
1908- slot_ptr_ = reinterpret_cast <slot_type *>(control_ptr_ + aligned_control_size, alignof (slot_type));
1909- hud::check ((u8 *)slot_ptr_ - (u8 *)control_ptr_ == aligned_control_size);
1904+ slot_ptr_ = reinterpret_cast <slot_type *>(hud::memory::align_address (reinterpret_cast <const uptr>(control_ptr_ + control_size), sizeof (slot_type)));
19101905 hud::check (hud::memory::is_pointer_aligned (slot_ptr_, alignof (slot_type)));
19111906 }
19121907 return control_size;
@@ -1918,18 +1913,17 @@ namespace hud
19181913 {
19191914 const usize control_size {control_size_for_max_count (max_slot_count)};
19201915 const usize slots_size {max_slot_count * sizeof (slot_type)};
1921- const uptr aligned_control_size {hud::memory::align_address (control_size, sizeof (slot_type))};
19221916
19231917 // In a constant-evaluated context, bit_cast cannot be used with pointers
19241918 // and allocation is done in two separate allocation
19251919 if (hud::is_constant_evaluated ())
19261920 {
1927- allocator_.template free <control_type>({control_ptr, aligned_control_size });
1921+ allocator_.template free <control_type>({control_ptr, control_size });
19281922 allocator_.template free <slot_type>({slot_ptr, slots_size});
19291923 }
19301924 else
19311925 {
1932- const usize aligned_allocation_size {aligned_control_size + slots_size};
1926+ const usize aligned_allocation_size {control_size + sizeof (slot_type) + slots_size};
19331927 allocator_.template free <control_type>({control_ptr, aligned_allocation_size});
19341928 }
19351929 }
0 commit comments