remove borrowck workarounds from the containers
This commit is contained in:
parent
4b6864f219
commit
ebe35f3873
|
@ -347,16 +347,27 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
|
|||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(stage0)]
|
||||
fn find_mut<'a>(&'a mut self, k: &K) -> Option<&'a mut V> {
|
||||
let idx = match self.bucket_for_key(k) {
|
||||
FoundEntry(idx) => idx,
|
||||
TableFull | FoundHole(_) => return None
|
||||
};
|
||||
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
|
||||
unsafe {
|
||||
Some(::cast::transmute_mut_region(self.mut_value_for_bucket(idx)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(not(stage0))]
|
||||
fn find_mut<'a>(&'a mut self, k: &K) -> Option<&'a mut V> {
|
||||
let idx = match self.bucket_for_key(k) {
|
||||
FoundEntry(idx) => idx,
|
||||
TableFull | FoundHole(_) => return None
|
||||
};
|
||||
Some(self.mut_value_for_bucket(idx))
|
||||
}
|
||||
|
||||
/// Insert a key-value pair into the map. An existing value for a
|
||||
/// key is replaced by the new value. Return true if the key did
|
||||
/// not already exist in the map.
|
||||
|
@ -429,6 +440,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
|||
|
||||
/// Return the value corresponding to the key in the map, or insert
|
||||
/// and return the value if it doesn't exist.
|
||||
#[cfg(stage0)]
|
||||
fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
|
@ -452,13 +464,43 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
|||
},
|
||||
};
|
||||
|
||||
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
|
||||
unsafe {
|
||||
::cast::transmute_region(self.value_for_bucket(idx))
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the value corresponding to the key in the map, or insert
|
||||
/// and return the value if it doesn't exist.
|
||||
#[cfg(not(stage0))]
|
||||
fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
// that we do not resize if this call to insert is
|
||||
// simply going to update a key in place. My sense
|
||||
// though is that it's worse to have to search through
|
||||
// buckets to find the right spot twice than to just
|
||||
// resize in this corner case.
|
||||
self.expand();
|
||||
}
|
||||
|
||||
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
||||
let idx = match self.bucket_for_key_with_hash(hash, &k) {
|
||||
TableFull => fail!(~"Internal logic error"),
|
||||
FoundEntry(idx) => idx,
|
||||
FoundHole(idx) => {
|
||||
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
|
||||
value: v});
|
||||
self.size += 1;
|
||||
idx
|
||||
},
|
||||
};
|
||||
|
||||
self.value_for_bucket(idx)
|
||||
}
|
||||
|
||||
/// Return the value corresponding to the key in the map, or create,
|
||||
/// insert, and return a new value if it doesn't exist.
|
||||
#[cfg(stage0)]
|
||||
fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) -> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
|
@ -483,11 +525,41 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
|||
},
|
||||
};
|
||||
|
||||
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
|
||||
unsafe {
|
||||
::cast::transmute_region(self.value_for_bucket(idx))
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the value corresponding to the key in the map, or create,
|
||||
/// insert, and return a new value if it doesn't exist.
|
||||
#[cfg(not(stage0))]
|
||||
fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) -> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
// that we do not resize if this call to insert is
|
||||
// simply going to update a key in place. My sense
|
||||
// though is that it's worse to have to search through
|
||||
// buckets to find the right spot twice than to just
|
||||
// resize in this corner case.
|
||||
self.expand();
|
||||
}
|
||||
|
||||
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
||||
let idx = match self.bucket_for_key_with_hash(hash, &k) {
|
||||
TableFull => fail!(~"Internal logic error"),
|
||||
FoundEntry(idx) => idx,
|
||||
FoundHole(idx) => {
|
||||
let v = f(&k);
|
||||
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
|
||||
value: v});
|
||||
self.size += 1;
|
||||
idx
|
||||
},
|
||||
};
|
||||
|
||||
self.value_for_bucket(idx)
|
||||
}
|
||||
|
||||
fn consume(&mut self, f: &fn(K, V)) {
|
||||
let mut buckets = ~[];
|
||||
self.buckets <-> buckets;
|
||||
|
|
|
@ -276,9 +276,9 @@ fn chunk(n: uint, idx: uint) -> uint {
|
|||
(n >> sh) & MASK
|
||||
}
|
||||
|
||||
fn find_mut<'r, T>(child: &'r mut Child<T>, key: uint, idx: uint)
|
||||
-> Option<&'r mut T> {
|
||||
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
|
||||
#[cfg(stage0)]
|
||||
fn find_mut<'r, T>(child: &'r mut Child<T>, key: uint, idx: uint) -> Option<&'r mut T> {
|
||||
unsafe {
|
||||
(match *child {
|
||||
External(_, ref value) => Some(cast::transmute_mut(value)),
|
||||
Internal(ref x) => find_mut(cast::transmute_mut(&x.children[chunk(key, idx)]),
|
||||
|
@ -288,6 +288,15 @@ fn find_mut<'r, T>(child: &'r mut Child<T>, key: uint, idx: uint)
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn find_mut<'r, T>(child: &'r mut Child<T>, key: uint, idx: uint) -> Option<&'r mut T> {
|
||||
match *child {
|
||||
External(_, ref mut value) => Some(value),
|
||||
Internal(ref mut x) => find_mut(&mut x.children[chunk(key, idx)], key, idx + 1),
|
||||
Nothing => None
|
||||
}
|
||||
}
|
||||
|
||||
fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T,
|
||||
idx: uint) -> bool {
|
||||
let mut tmp = Nothing;
|
||||
|
|
Loading…
Reference in New Issue