Skip to content

Commit

Permalink
Merge pull request #80 from lumen/master
Browse files Browse the repository at this point in the history
Fix unnecessary recursion in iterators
  • Loading branch information
xacrimon authored Apr 19, 2020
2 parents 96fad2b + a0ba18f commit 99cc02e
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@ impl<K: Eq + Hash, V, S: BuildHasher + Clone> Iterator for OwningIter<K, V, S> {

#[inline]
fn next(&mut self) -> Option<Self::Item> {
if let Some(current) = self.current.as_mut() {
if let Some((k, v)) = current.next() {
return Some((k, v.into_inner()));
loop {
if let Some(current) = self.current.as_mut() {
if let Some((k, v)) = current.next() {
return Some((k, v.into_inner()));
}
}
}

if self.shard_i == self.map._shard_count() {
return None;
}
if self.shard_i == self.map._shard_count() {
return None;
}

//let guard = unsafe { self.map._yield_read_shard(self.shard_i) };
let mut shard_wl = unsafe { self.map._yield_write_shard(self.shard_i) };
let hasher = self.map._hasher();
let map = mem::replace(&mut *shard_wl, HashMap::with_hasher(hasher));
drop(shard_wl);
let iter = map.into_iter();
//unsafe { ptr::write(&mut self.current, Some((arcee, iter))); }
self.current = Some(iter);
self.shard_i += 1;

self.next()
//let guard = unsafe { self.map._yield_read_shard(self.shard_i) };
let mut shard_wl = unsafe { self.map._yield_write_shard(self.shard_i) };
let hasher = self.map._hasher();
let map = mem::replace(&mut *shard_wl, HashMap::with_hasher(hasher));
drop(shard_wl);
let iter = map.into_iter();
//unsafe { ptr::write(&mut self.current, Some((arcee, iter))); }
self.current = Some(iter);
self.shard_i += 1;
}
}
}

Expand Down Expand Up @@ -155,24 +155,24 @@ impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iter

#[inline]
fn next(&mut self) -> Option<Self::Item> {
if let Some(current) = self.current.as_mut() {
if let Some((k, v)) = current.1.next() {
let guard = current.0.clone();
return Some(RefMulti::new(guard, k, v.get()));
loop {
if let Some(current) = self.current.as_mut() {
if let Some((k, v)) = current.1.next() {
let guard = current.0.clone();
return Some(RefMulti::new(guard, k, v.get()));
}
}
}

if self.shard_i == self.map._shard_count() {
return None;
}

let guard = unsafe { self.map._yield_read_shard(self.shard_i) };
let sref: &HashMap<K, V, S> = unsafe { util::change_lifetime_const(&*guard) };
let iter = sref.iter();
self.current = Some((Arc::new(guard), iter));
self.shard_i += 1;
if self.shard_i == self.map._shard_count() {
return None;
}

self.next()
let guard = unsafe { self.map._yield_read_shard(self.shard_i) };
let sref: &HashMap<K, V, S> = unsafe { util::change_lifetime_const(&*guard) };
let iter = sref.iter();
self.current = Some((Arc::new(guard), iter));
self.shard_i += 1;
}
}
}

Expand Down Expand Up @@ -231,28 +231,28 @@ impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iter

#[inline]
fn next(&mut self) -> Option<Self::Item> {
if let Some(current) = self.current.as_mut() {
if let Some((k, v)) = current.1.next() {
let guard = current.0.clone();
unsafe {
let k = util::change_lifetime_const(k);
let v = &mut *v.as_ptr();
return Some(RefMutMulti::new(guard, k, v));
loop {
if let Some(current) = self.current.as_mut() {
if let Some((k, v)) = current.1.next() {
let guard = current.0.clone();
unsafe {
let k = util::change_lifetime_const(k);
let v = &mut *v.as_ptr();
return Some(RefMutMulti::new(guard, k, v));
}
}
}
}

if self.shard_i == self.map._shard_count() {
return None;
}

let mut guard = unsafe { self.map._yield_write_shard(self.shard_i) };
let sref: &mut HashMap<K, V, S> = unsafe { util::change_lifetime_mut(&mut *guard) };
let iter = sref.iter_mut();
self.current = Some((Arc::new(guard), iter));
self.shard_i += 1;
if self.shard_i == self.map._shard_count() {
return None;
}

self.next()
let mut guard = unsafe { self.map._yield_write_shard(self.shard_i) };
let sref: &mut HashMap<K, V, S> = unsafe { util::change_lifetime_mut(&mut *guard) };
let iter = sref.iter_mut();
self.current = Some((Arc::new(guard), iter));
self.shard_i += 1;
}
}
}

Expand Down

0 comments on commit 99cc02e

Please sign in to comment.