Skip to content

Commit

Permalink
Fix raw
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Jan 14, 2021
1 parent 9277f65 commit d033e84
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ impl<T> RawIter<T> {
return;
}

if self.iter.inner.next_ctrl < self.iter.inner.end
if self.iter.next_ctrl < self.iter.end
&& b.as_ptr() <= self.iter.data.next_n(Group::WIDTH).as_ptr()
{
// The iterator has not yet reached the bucket's group.
Expand All @@ -1818,7 +1818,7 @@ impl<T> RawIter<T> {
// To do that, we need to find its control byte. We know that self.iter.data is
// at self.iter.next_ctrl - Group::WIDTH, so we work from there:
let offset = offset_from(self.iter.data.as_ptr(), b.as_ptr());
let ctrl = self.iter.inner.next_ctrl.sub(Group::WIDTH).add(offset);
let ctrl = self.iter.next_ctrl.sub(Group::WIDTH).add(offset);
// This method should be called _before_ a removal, or _after_ an insert,
// so in both cases the ctrl byte should indicate that the bucket is full.
assert!(is_full(*ctrl));
Expand All @@ -1841,7 +1841,7 @@ impl<T> RawIter<T> {
// - Otherwise, update the iterator cached group so that it won't
// yield a to-be-removed bucket, or _will_ yield a to-be-added bucket.
// We'll also need ot update the item count accordingly.
if let Some(index) = self.iter.inner.current_group.lowest_set_bit() {
if let Some(index) = self.iter.current_group.lowest_set_bit() {
let next_bucket = self.iter.data.next_n(index);
if b.as_ptr() > next_bucket.as_ptr() {
// The toggled bucket is "before" the bucket the iterator would yield next. We
Expand All @@ -1862,7 +1862,7 @@ impl<T> RawIter<T> {
// Instead, we _just_ flip the bit for the particular bucket the caller asked
// us to reflect.
let our_bit = offset_from(self.iter.data.as_ptr(), b.as_ptr());
let was_full = self.iter.inner.current_group.flip(our_bit);
let was_full = self.iter.current_group.flip(our_bit);
debug_assert_ne!(was_full, is_insert);

if is_insert {
Expand All @@ -1874,16 +1874,10 @@ impl<T> RawIter<T> {
if cfg!(debug_assertions) {
if b.as_ptr() == next_bucket.as_ptr() {
// The removed bucket should no longer be next
debug_assert_ne!(
self.iter.inner.current_group.lowest_set_bit(),
Some(index)
);
debug_assert_ne!(self.iter.current_group.lowest_set_bit(), Some(index));
} else {
// We should not have changed what bucket comes next.
debug_assert_eq!(
self.iter.inner.current_group.lowest_set_bit(),
Some(index)
);
debug_assert_eq!(self.iter.current_group.lowest_set_bit(), Some(index));
}
}
}
Expand Down

0 comments on commit d033e84

Please sign in to comment.