Make push_back() more efficient

This commit is contained in:
Gennaro Prota
2025-09-18 16:40:47 +02:00
parent 3ff4a319d9
commit 5f62214ad5

View File

@@ -750,8 +750,13 @@ void
dynamic_bitset< Block, AllocatorOrContainer >:: dynamic_bitset< Block, AllocatorOrContainer >::
push_back( bool bit ) push_back( bool bit )
{ {
const size_type sz = size(); const int extra_bits = count_extra_bits();
resize( sz + 1, bit ); if ( extra_bits == 0 ) {
m_bits.push_back( Block( bit ) );
} else {
m_bits.back() |= ( Block( bit ) << extra_bits );
}
++ m_num_bits;
} }
template< typename Block, typename AllocatorOrContainer > template< typename Block, typename AllocatorOrContainer >