Skip to content

Commit 3e7a514

Browse files
committed
Fix inconsistent-iteration hazard in map.rs
Closes #2049
1 parent 683085b commit 3e7a514

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/libstd/map.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,16 @@ mod chained {
257257
fn size() -> uint { self.count }
258258

259259
fn insert(k: K, v: V) -> bool {
260-
let nchains = vec::len(self.chains);
261-
let load = {num: (self.count + 1u) as int, den: nchains as int};
262-
// Structural consts would be nice. This is a const 3/4
263-
// load factor that we compare against.
264-
if !util::rational_leq(load, {num:3, den:4}) { rehash(self); }
265-
ret insert(self, k, v);
260+
let grew = insert(self, k, v);
261+
if grew {
262+
let nchains = vec::len(self.chains);
263+
let load = {num: (self.count + 1u) as int,
264+
den: nchains as int};
265+
// Structural consts would be nice. This is a const 3/4
266+
// load factor that we compare against.
267+
if !util::rational_leq(load, {num:3, den:4}) { rehash(self); }
268+
}
269+
grew
266270
}
267271

268272
fn contains_key(k: K) -> bool { option::is_some(get(self, k)) }

0 commit comments

Comments
 (0)