diff --git a/roaring/roaring.go b/roaring/roaring.go index 7b382ec6f..575515743 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -659,8 +659,9 @@ func (b *Bitmap) unionIntoTarget(target *Bitmap, others ...*Bitmap) { // Once we've acquired a bitmap container (either by reusing the existing one // or allocating a new one) then the last step is to iterate through all the // other containers to see which ones have the same key, and union all of them - // into the target bitmap container. - for j, jIter := range bitmapIters { + // into the target bitmap container. Only need to loop starting from i because + // anything previous to that has already been handled. + for j, jIter := range bitmapIters[i:] { jKey, jContainer := jIter.iter.Value() if iKey == jKey {