Skip to content

Commit

Permalink
auto merge of #6292 : thestinger/rust/cleanup, r=brson
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed May 7, 2013
2 parents 5063928 + d800147 commit 452817b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 12 deletions.
8 changes: 4 additions & 4 deletions mk/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ ifeq ($(CFG_ADB_DEVICE_STATUS),true)
ifdef VERBOSE
ADB = adb $(1)
ADB_PUSH = adb push $(1) $(2)
ADB_SHELL = adb shell $(1) $(2)
ADB_SHELL = adb shell $(1) $(2)
else
ADB = $(Q)$(call E, adb $(1)) && adb $(1) 1>/dev/null
ADB = $(Q)$(call E, adb $(1)) && adb $(1) 1>/dev/null
ADB_PUSH = $(Q)$(call E, adb push $(1)) && adb push $(1) $(2) 1>/dev/null
ADB_SHELL = $(Q)$(call E, adb shell $(1) $(2)) && adb shell $(1) $(2) 1>/dev/null
endif
Expand Down Expand Up @@ -222,8 +222,8 @@ install-runtime-target: \
install-runtime-target-arm-linux-androideabi-cleanup \
install-runtime-target-arm-linux-androideabi-host-$(CFG_BUILD_TRIPLE)
else
install-runtime-target:
install-runtime-target:
@echo "No device to install runtime library"
@echo
@echo
endif
endif
4 changes: 2 additions & 2 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ endef
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call DEF_TARGET_COMMANDS,$(target))))

# Target platform specific variables
# Target platform specific variables
# for arm-linux-androidabi
define DEF_ADB_DEVICE_STATUS
CFG_ADB_DEVICE_STATUS=$(1)
Expand Down Expand Up @@ -402,7 +402,7 @@ $(foreach host,$(CFG_HOST_TRIPLES), \
$(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
), \
$(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
))))))
))))))


######################################################################
Expand Down
78 changes: 75 additions & 3 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,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.
Expand Down Expand Up @@ -424,6 +435,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
Expand All @@ -447,13 +459,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
Expand All @@ -478,11 +520,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;
Expand Down
15 changes: 12 additions & 3 deletions src/libcore/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,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)]),
Expand All @@ -301,6 +301,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) -> Option<T> {
let mut tmp = Nothing;
Expand Down

0 comments on commit 452817b

Please sign in to comment.