FastLED 3.9.15
Loading...
Searching...
No Matches

◆ resize()

FL_DISABLE_WARNING_POP FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_NULL_DEREFERENCE void fl::bitset_dynamic::resize ( fl::u32 new_size)
inline

Definition at line 117 of file bitset_dynamic.h.

117 {
118 if (new_size == _size)
119 return;
120
121 fl::u32 new_block_count = (new_size + bits_per_block - 1) / bits_per_block;
122
123 if (new_block_count != _block_count) {
124 block_type *new_blocks = new block_type[new_block_count]; // ok bare allocation (array new for unique_ptr)
125 fl::memset(new_blocks, 0, new_block_count * sizeof(block_type));
126
127 if (_blocks) {
128 fl::u32 copy_blocks = fl::min(_block_count, new_block_count);
129 fl::memcpy(new_blocks, _blocks.get(), copy_blocks * sizeof(block_type));
130 }
131
132 _blocks.reset(new_blocks);
133 _block_count = new_block_count;
134 }
135
136 _size = new_size;
137
138 // Clear any bits beyond the new size
139 if (_blocks && _block_count > 0 && _size % bits_per_block != 0) {
140 fl::u32 last_block_idx = (_size - 1) / bits_per_block;
141 fl::u32 last_bit_pos = (_size - 1) % bits_per_block;
142 block_type mask =
143 static_cast<block_type>((static_cast<block_type>(1) << (last_bit_pos + 1)) - 1);
144 _blocks[last_block_idx] &= mask;
145 }
146 }
fl::unique_ptr< block_type[]> _blocks
static constexpr fl::u32 bits_per_block
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT
void * memset(void *s, int c, size_t n) FL_NOEXCEPT

References _block_count, _blocks, _size, bits_per_block, FL_NOEXCEPT, fl::memcpy(), fl::memset(), and fl::min().

Referenced by bitset_dynamic(), bitset_dynamic(), assign(), operator=(), pop_back(), and push_back().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: