@@ -89,7 +89,7 @@ impl<K: Ord, V> Mutable for TreeMap<K, V> {
89
89
90
90
impl < K : Ord , V > Map < K , V > for TreeMap < K , V > {
91
91
fn find < ' a > ( & ' a self , key : & K ) -> Option < & ' a V > {
92
- let mut current: & ' a Option < Box < TreeNode < K , V > > > = & self . root ;
92
+ let mut current = & self . root ;
93
93
loop {
94
94
match * current {
95
95
Some ( ref r) => {
@@ -108,7 +108,20 @@ impl<K: Ord, V> Map<K, V> for TreeMap<K, V> {
108
108
impl < K : Ord , V > MutableMap < K , V > for TreeMap < K , V > {
109
109
#[ inline]
110
110
fn find_mut < ' a > ( & ' a mut self , key : & K ) -> Option < & ' a mut V > {
111
- find_mut ( & mut self . root , key)
111
+ let mut current = & mut self . root ;
112
+ loop {
113
+ let temp = current; // hack to appease borrowck
114
+ match * temp {
115
+ Some ( ref mut r) => {
116
+ match key. cmp ( & r. key ) {
117
+ Less => current = & mut r. left ,
118
+ Greater => current = & mut r. right ,
119
+ Equal => return Some ( & mut r. value )
120
+ }
121
+ }
122
+ None => return None
123
+ }
124
+ }
112
125
}
113
126
114
127
fn swap ( & mut self , key : K , value : V ) -> Option < V > {
@@ -840,21 +853,6 @@ fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
840
853
}
841
854
}
842
855
843
- fn find_mut < ' r , K : Ord , V > ( node : & ' r mut Option < Box < TreeNode < K , V > > > ,
844
- key : & K )
845
- -> Option < & ' r mut V > {
846
- match * node {
847
- Some ( ref mut x) => {
848
- match key. cmp ( & x. key ) {
849
- Less => find_mut ( & mut x. left , key) ,
850
- Greater => find_mut ( & mut x. right , key) ,
851
- Equal => Some ( & mut x. value ) ,
852
- }
853
- }
854
- None => None
855
- }
856
- }
857
-
858
856
fn insert < K : Ord , V > ( node : & mut Option < Box < TreeNode < K , V > > > ,
859
857
key : K , value : V ) -> Option < V > {
860
858
match * node {
0 commit comments