Skip to content

Commit 717f9a5

Browse files
committed
---
yaml --- r: 46900 b: refs/heads/try c: a165f88 h: refs/heads/master v: v3
1 parent 50c56d5 commit 717f9a5

File tree

3 files changed

+38
-99
lines changed

3 files changed

+38
-99
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3bbcac322669cff3abde5be937cc4ec3860f3985
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
5-
refs/heads/try: 91c59f5c9a6d1fe72a18768b074fcb16542e0ca1
5+
refs/heads/try: a165f882726d86ad4c65a5b72daa5b457af12e6c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/hashmap.rs

Lines changed: 33 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,19 @@ pub mod linear {
108108
}
109109

110110
#[inline(always)]
111-
pure fn bucket_for_key(&self, k: &K) -> SearchResult {
111+
pure fn bucket_for_key(&self, buckets: &[Option<Bucket<K, V>>],
112+
k: &K) -> SearchResult {
112113
let hash = k.hash_keyed(self.k0, self.k1) as uint;
113-
self.bucket_for_key_with_hash(hash, k)
114+
self.bucket_for_key_with_hash(buckets, hash, k)
114115
}
115116

116117
#[inline(always)]
117118
pure fn bucket_for_key_with_hash(&self,
119+
buckets: &[Option<Bucket<K, V>>],
118120
hash: uint,
119121
k: &K) -> SearchResult {
120122
let _ = for self.bucket_sequence(hash) |i| {
121-
match self.buckets[i] {
123+
match buckets[i] {
122124
Some(ref bkt) => if bkt.hash == hash && *k == bkt.key {
123125
return FoundEntry(i);
124126
},
@@ -155,19 +157,11 @@ pub mod linear {
155157
}
156158
}
157159

158-
#[inline(always)]
159-
pure fn value_for_bucket(&self, idx: uint) -> &self/V {
160-
match self.buckets[idx] {
161-
Some(ref bkt) => &bkt.value,
162-
None => die!(~"LinearMap::find: internal logic error"),
163-
}
164-
}
165-
166160
/// Inserts the key value pair into the buckets.
167161
/// Assumes that there will be a bucket.
168162
/// True if there was no previous entry with that key
169163
fn insert_internal(&mut self, hash: uint, k: K, v: V) -> bool {
170-
match self.bucket_for_key_with_hash(hash, &k) {
164+
match self.bucket_for_key_with_hash(self.buckets, hash, &k) {
171165
TableFull => { die!(~"Internal logic error"); }
172166
FoundHole(idx) => {
173167
debug!("insert fresh (%?->%?) at idx %?, hash %?",
@@ -202,7 +196,8 @@ pub mod linear {
202196
//
203197
// I found this explanation elucidating:
204198
// http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf
205-
let mut idx = match self.bucket_for_key_with_hash(hash, k) {
199+
let mut idx = match self.bucket_for_key_with_hash(self.buckets,
200+
hash, k) {
206201
TableFull | FoundHole(_) => return None,
207202
FoundEntry(idx) => idx
208203
};
@@ -278,7 +273,7 @@ pub mod linear {
278273
impl <K: Hash IterBytes Eq, V> LinearMap<K, V>: Map<K, V> {
279274
/// Return true if the map contains a value for the specified key
280275
pure fn contains_key(&self, k: &K) -> bool {
281-
match self.bucket_for_key(k) {
276+
match self.bucket_for_key(self.buckets, k) {
282277
FoundEntry(_) => {true}
283278
TableFull | FoundHole(_) => {false}
284279
}
@@ -296,9 +291,20 @@ pub mod linear {
296291
297292
/// Return the value corresponding to the key in the map
298293
pure fn find(&self, k: &K) -> Option<&self/V> {
299-
match self.bucket_for_key(k) {
300-
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
301-
TableFull | FoundHole(_) => None,
294+
match self.bucket_for_key(self.buckets, k) {
295+
FoundEntry(idx) => {
296+
match self.buckets[idx] {
297+
Some(ref bkt) => {
298+
Some(&bkt.value)
299+
}
300+
None => {
301+
die!(~"LinearMap::find: internal logic error")
302+
}
303+
}
304+
}
305+
TableFull | FoundHole(_) => {
306+
None
307+
}
302308
}
303309
}
304310
@@ -358,63 +364,6 @@ pub mod linear {
358364
old_value
359365
}
360366
361-
/// Return the value corresponding to the key in the map, or insert
362-
/// and return the value if it doesn't exist.
363-
fn find_or_insert(&mut self, k: K, v: V) -> &self/V {
364-
if self.size >= self.resize_at {
365-
// n.b.: We could also do this after searching, so
366-
// that we do not resize if this call to insert is
367-
// simply going to update a key in place. My sense
368-
// though is that it's worse to have to search through
369-
// buckets to find the right spot twice than to just
370-
// resize in this corner case.
371-
self.expand();
372-
}
373-
374-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
375-
let idx = match self.bucket_for_key_with_hash(hash, &k) {
376-
TableFull => die!(~"Internal logic error"),
377-
FoundEntry(idx) => idx,
378-
FoundHole(idx) => {
379-
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
380-
value: v});
381-
self.size += 1;
382-
idx
383-
},
384-
};
385-
386-
self.value_for_bucket(idx)
387-
}
388-
389-
/// Return the value corresponding to the key in the map, or create,
390-
/// insert, and return a new value if it doesn't exist.
391-
fn find_or_insert_with(&mut self, k: K, f: fn(&K) -> V) -> &self/V {
392-
if self.size >= self.resize_at {
393-
// n.b.: We could also do this after searching, so
394-
// that we do not resize if this call to insert is
395-
// simply going to update a key in place. My sense
396-
// though is that it's worse to have to search through
397-
// buckets to find the right spot twice than to just
398-
// resize in this corner case.
399-
self.expand();
400-
}
401-
402-
let hash = k.hash_keyed(self.k0, self.k1) as uint;
403-
let idx = match self.bucket_for_key_with_hash(hash, &k) {
404-
TableFull => die!(~"Internal logic error"),
405-
FoundEntry(idx) => idx,
406-
FoundHole(idx) => {
407-
let v = f(&k);
408-
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
409-
value: v});
410-
self.size += 1;
411-
idx
412-
},
413-
};
414-
415-
self.value_for_bucket(idx)
416-
}
417-
418367
fn consume(&mut self, f: fn(K, V)) {
419368
let mut buckets = ~[];
420369
self.buckets <-> buckets;
@@ -572,7 +521,7 @@ mod test_map {
572521
use uint;
573522

574523
#[test]
575-
pub fn test_insert() {
524+
pub fn inserts() {
576525
let mut m = LinearMap::new();
577526
assert m.insert(1, 2);
578527
assert m.insert(2, 4);
@@ -581,7 +530,7 @@ mod test_map {
581530
}
582531

583532
#[test]
584-
pub fn test_insert_overwrite() {
533+
pub fn overwrite() {
585534
let mut m = LinearMap::new();
586535
assert m.insert(1, 2);
587536
assert *m.get(&1) == 2;
@@ -590,7 +539,7 @@ mod test_map {
590539
}
591540

592541
#[test]
593-
pub fn test_insert_conflicts() {
542+
pub fn conflicts() {
594543
let mut m = linear::linear_map_with_capacity(4);
595544
assert m.insert(1, 2);
596545
assert m.insert(5, 3);
@@ -601,7 +550,7 @@ mod test_map {
601550
}
602551

603552
#[test]
604-
pub fn test_conflict_remove() {
553+
pub fn conflict_remove() {
605554
let mut m = linear::linear_map_with_capacity(4);
606555
assert m.insert(1, 2);
607556
assert m.insert(5, 3);
@@ -612,7 +561,7 @@ mod test_map {
612561
}
613562

614563
#[test]
615-
pub fn test_is_empty() {
564+
pub fn empty() {
616565
let mut m = linear::linear_map_with_capacity(4);
617566
assert m.insert(1, 2);
618567
assert !m.is_empty();
@@ -621,37 +570,23 @@ mod test_map {
621570
}
622571

623572
#[test]
624-
pub fn test_pop() {
573+
pub fn pops() {
625574
let mut m = LinearMap::new();
626575
m.insert(1, 2);
627576
assert m.pop(&1) == Some(2);
628577
assert m.pop(&1) == None;
629578
}
630579

631580
#[test]
632-
pub fn test_swap() {
581+
pub fn swaps() {
633582
let mut m = LinearMap::new();
634583
assert m.swap(1, 2) == None;
635584
assert m.swap(1, 3) == Some(2);
636585
assert m.swap(1, 4) == Some(3);
637586
}
638587

639588
#[test]
640-
pub fn test_find_or_insert() {
641-
let mut m = LinearMap::new::<int, int>();
642-
assert m.find_or_insert(1, 2) == &2;
643-
assert m.find_or_insert(1, 3) == &2;
644-
}
645-
646-
#[test]
647-
pub fn test_find_or_insert_with() {
648-
let mut m = LinearMap::new::<int, int>();
649-
assert m.find_or_insert_with(1, |_| 2) == &2;
650-
assert m.find_or_insert_with(1, |_| 3) == &2;
651-
}
652-
653-
#[test]
654-
pub fn test_consume() {
589+
pub fn consumes() {
655590
let mut m = LinearMap::new();
656591
assert m.insert(1, 2);
657592
assert m.insert(2, 3);
@@ -666,7 +601,7 @@ mod test_map {
666601
}
667602

668603
#[test]
669-
pub fn test_iterate() {
604+
pub fn iterate() {
670605
let mut m = linear::linear_map_with_capacity(4);
671606
for uint::range(0, 32) |i| {
672607
assert m.insert(i, i*2);
@@ -680,7 +615,7 @@ mod test_map {
680615
}
681616

682617
#[test]
683-
pub fn test_find() {
618+
pub fn find() {
684619
let mut m = LinearMap::new();
685620
assert m.find(&1).is_none();
686621
m.insert(1, 2);

branches/try/src/librustc/middle/ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,10 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
19321932
Some(tc) => { return *tc; }
19331933
None => {}
19341934
}
1935+
match cx.tc_cache.find(&ty_id) { // Must check both caches!
1936+
Some(tc) => { return *tc; }
1937+
None => {}
1938+
}
19351939
cache.insert(ty_id, TC_NONE);
19361940
19371941
debug!("computing contents of %s", ty_to_str(cx, ty));

0 commit comments

Comments
 (0)