@@ -144,19 +144,13 @@ contains
144144 integer(bits_kind) :: bit_count
145145 class(bitset_large), intent(in) :: self
146146
147- integer(bits_kind) :: block_ , pos
147+ integer(bits_kind) :: nblocks , pos
148148
149- bit_count = 0
150- do block_ = 1_bits_kind, size(self % blocks, kind=bits_kind) - 1
151- do pos = 0, block_size-1
152- if ( btest( self % blocks(block_), pos ) ) &
153- bit_count = bit_count + 1
154- end do
155-
156- end do
149+ nblocks = size( self % blocks, kind=bits_kind )
150+ bit_count = sum( popcnt( self % blocks(1:nblocks-1) ) )
157151
158- do pos = 0_bits_kind, self % num_bits - (block_ -1)*block_size - 1
159- if ( btest( self % blocks(block_ ), pos ) ) bit_count = bit_count + 1
152+ do pos = 0_bits_kind, self % num_bits - (nblocks -1)*block_size - 1
153+ if ( btest( self % blocks(nblocks ), pos ) ) bit_count = bit_count + 1
160154 end do
161155
162156 end function bit_count_large
@@ -1051,7 +1045,7 @@ contains
10511045 pure module subroutine set_range_large(self, start_pos, stop_pos)
10521046!
10531047! Sets all valid bits to 1 from the START_POS to the STOP_POS positions
1054- ! in SELF. If STOP_POA < START_POS no bits are changed. Positions outside
1048+ ! in SELF. If STOP_POS < START_POS no bits are changed. Positions outside
10551049! the range 0 to BITS(SELF)-1 are ignored.
10561050!
10571051 class(bitset_large), intent(inout) :: self
0 commit comments