Skip to content

Commit 6610f5b

Browse files
committed
Make push_back() more efficient
1 parent 5fa946c commit 6610f5b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/boost/dynamic_bitset/impl/dynamic_bitset.ipp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,13 @@ void
750750
dynamic_bitset< Block, AllocatorOrContainer >::
751751
push_back( bool bit )
752752
{
753-
const size_type sz = size();
754-
resize( sz + 1, bit );
753+
const int extra_bits = count_extra_bits();
754+
if ( extra_bits == 0 ) {
755+
m_bits.push_back( Block( bit ) );
756+
} else {
757+
m_bits.back() |= ( Block( bit ) << extra_bits );
758+
}
759+
++ m_num_bits;
755760
}
756761

757762
template< typename Block, typename AllocatorOrContainer >

0 commit comments

Comments
 (0)