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 120 of file bitset_dynamic.h.

120 {
121 if (new_size == _size)
122 return;
123
124 fl::u32 new_block_count = (new_size + bits_per_block - 1) / bits_per_block;
125
126 if (new_block_count != _block_count) {
127 block_type *new_blocks = new block_type[new_block_count];
128 fl::memfill(new_blocks, 0, new_block_count * sizeof(block_type));
129
130 if (_blocks) {
131 fl::u32 copy_blocks = MIN(_block_count, new_block_count);
132 memcpy(new_blocks, _blocks, copy_blocks * sizeof(block_type));
133 }
134
135 delete[] _blocks;
136 _blocks = new_blocks;
137 _block_count = new_block_count;
138 }
139
140 _size = new_size;
141
142 // Clear any bits beyond the new size
143 if (_blocks && _block_count > 0 && _size % bits_per_block != 0) {
144 fl::u32 last_block_idx = (_size - 1) / bits_per_block;
145 fl::u32 last_bit_pos = (_size - 1) % bits_per_block;
146 block_type mask =
147 static_cast<block_type>((static_cast<block_type>(1) << (last_bit_pos + 1)) - 1);
148 _blocks[last_block_idx] &= mask;
149 }
150 }
block_type * _blocks
static constexpr fl::u32 bits_per_block
#define MIN(a, b)
Definition math_macros.h:41
void * memfill(void *ptr, int value, fl::size num)
Definition memfill.h:11

References _block_count, _blocks, _size, bits_per_block, fl::memfill(), and MIN.

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

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