@@ -802,7 +802,11 @@ where
802
802
K : Borrow < Q > ,
803
803
Q : Hash + Eq ,
804
804
{
805
- self . get_key_value ( k) . map ( |( _, v) | v)
805
+ // Avoid `Option::map` because it bloats LLVM IR.
806
+ match self . get_key_value ( k) {
807
+ Some ( ( _, v) ) => Some ( v) ,
808
+ None => None ,
809
+ }
806
810
}
807
811
808
812
/// Returns the key-value pair corresponding to the supplied key.
@@ -831,12 +835,14 @@ where
831
835
Q : Hash + Eq ,
832
836
{
833
837
let hash = make_hash ( & self . hash_builder , k) ;
834
- self . table
835
- . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) )
836
- . map ( | item| unsafe {
838
+ // Avoid `Option::map` because it bloats LLVM IR.
839
+ match self . table . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) ) {
840
+ Some ( item) => unsafe {
837
841
let & ( ref key, ref value) = item. as_ref ( ) ;
838
- ( key, value)
839
- } )
842
+ Some ( ( key, value) )
843
+ }
844
+ None => None ,
845
+ }
840
846
}
841
847
842
848
/// Returns the key-value pair corresponding to the supplied key, with a mutable reference to value.
@@ -869,12 +875,14 @@ where
869
875
Q : Hash + Eq ,
870
876
{
871
877
let hash = make_hash ( & self . hash_builder , k) ;
872
- self . table
873
- . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) )
874
- . map ( | item| unsafe {
878
+ // Avoid `Option::map` because it bloats LLVM IR.
879
+ match self . table . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) ) {
880
+ Some ( item) => unsafe {
875
881
let & mut ( ref key, ref mut value) = item. as_mut ( ) ;
876
- ( key, value)
877
- } )
882
+ Some ( ( key, value) )
883
+ }
884
+ None => None ,
885
+ }
878
886
}
879
887
880
888
/// Returns `true` if the map contains a value for the specified key.
@@ -933,9 +941,11 @@ where
933
941
Q : Hash + Eq ,
934
942
{
935
943
let hash = make_hash ( & self . hash_builder , k) ;
936
- self . table
937
- . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) )
938
- . map ( |item| unsafe { & mut item. as_mut ( ) . 1 } )
944
+ // Avoid `Option::map` because it bloats LLVM IR.
945
+ match self . table . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) ) {
946
+ Some ( item) => Some ( unsafe { & mut item. as_mut ( ) . 1 } ) ,
947
+ None => None ,
948
+ }
939
949
}
940
950
941
951
/// Inserts a key-value pair into the map.
@@ -1004,7 +1014,11 @@ where
1004
1014
K : Borrow < Q > ,
1005
1015
Q : Hash + Eq ,
1006
1016
{
1007
- self . remove_entry ( k) . map ( |( _, v) | v)
1017
+ // Avoid `Option::map` because it bloats LLVM IR.
1018
+ match self . remove_entry ( k) {
1019
+ Some ( ( _, v) ) => Some ( v) ,
1020
+ None => None ,
1021
+ }
1008
1022
}
1009
1023
1010
1024
/// Removes a key from the map, returning the stored key and value if the
@@ -1561,13 +1575,13 @@ impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
1561
1575
where
1562
1576
F : FnMut ( & K ) -> bool ,
1563
1577
{
1564
- self . map
1565
- . table
1566
- . find ( hash, |( k, _) | is_match ( k) )
1567
- . map ( |item| unsafe {
1578
+ match self . map . table . find ( hash, |( k, _) | is_match ( k) ) {
1579
+ Some ( item) => unsafe {
1568
1580
let & ( ref key, ref value) = item. as_ref ( ) ;
1569
- ( key, value)
1570
- } )
1581
+ Some ( ( key, value) )
1582
+ }
1583
+ None => None ,
1584
+ }
1571
1585
}
1572
1586
1573
1587
/// Access an entry by hash.
@@ -2030,10 +2044,14 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
2030
2044
2031
2045
#[ cfg_attr( feature = "inline-more" , inline) ]
2032
2046
fn next ( & mut self ) -> Option < ( & ' a K , & ' a V ) > {
2033
- self . inner . next ( ) . map ( |x| unsafe {
2034
- let r = x. as_ref ( ) ;
2035
- ( & r. 0 , & r. 1 )
2036
- } )
2047
+ // Avoid `Option::map` because it bloats LLVM IR.
2048
+ match self . inner . next ( ) {
2049
+ Some ( x) => unsafe {
2050
+ let r = x. as_ref ( ) ;
2051
+ Some ( ( & r. 0 , & r. 1 ) )
2052
+ }
2053
+ None => None ,
2054
+ }
2037
2055
}
2038
2056
#[ cfg_attr( feature = "inline-more" , inline) ]
2039
2057
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -2054,10 +2072,14 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
2054
2072
2055
2073
#[ cfg_attr( feature = "inline-more" , inline) ]
2056
2074
fn next ( & mut self ) -> Option < ( & ' a K , & ' a mut V ) > {
2057
- self . inner . next ( ) . map ( |x| unsafe {
2058
- let r = x. as_mut ( ) ;
2059
- ( & r. 0 , & mut r. 1 )
2060
- } )
2075
+ // Avoid `Option::map` because it bloats LLVM IR.
2076
+ match self . inner . next ( ) {
2077
+ Some ( x) => unsafe {
2078
+ let r = x. as_mut ( ) ;
2079
+ Some ( ( & r. 0 , & mut r. 1 ) )
2080
+ }
2081
+ None => None ,
2082
+ }
2061
2083
}
2062
2084
#[ cfg_attr( feature = "inline-more" , inline) ]
2063
2085
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -2113,7 +2135,11 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
2113
2135
2114
2136
#[ cfg_attr( feature = "inline-more" , inline) ]
2115
2137
fn next ( & mut self ) -> Option < & ' a K > {
2116
- self . inner . next ( ) . map ( |( k, _) | k)
2138
+ // Avoid `Option::map` because it bloats LLVM IR.
2139
+ match self . inner . next ( ) {
2140
+ Some ( ( k, _) ) => Some ( k) ,
2141
+ None => None ,
2142
+ }
2117
2143
}
2118
2144
#[ cfg_attr( feature = "inline-more" , inline) ]
2119
2145
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -2133,7 +2159,11 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
2133
2159
2134
2160
#[ cfg_attr( feature = "inline-more" , inline) ]
2135
2161
fn next ( & mut self ) -> Option < & ' a V > {
2136
- self . inner . next ( ) . map ( |( _, v) | v)
2162
+ // Avoid `Option::map` because it bloats LLVM IR.
2163
+ match self . inner . next ( ) {
2164
+ Some ( ( _, v) ) => Some ( v) ,
2165
+ None => None ,
2166
+ }
2137
2167
}
2138
2168
#[ cfg_attr( feature = "inline-more" , inline) ]
2139
2169
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -2153,7 +2183,11 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
2153
2183
2154
2184
#[ cfg_attr( feature = "inline-more" , inline) ]
2155
2185
fn next ( & mut self ) -> Option < & ' a mut V > {
2156
- self . inner . next ( ) . map ( |( _, v) | v)
2186
+ // Avoid `Option::map` because it bloats LLVM IR.
2187
+ match self . inner . next ( ) {
2188
+ Some ( ( _, v) ) => Some ( v) ,
2189
+ None => None ,
2190
+ }
2157
2191
}
2158
2192
#[ cfg_attr( feature = "inline-more" , inline) ]
2159
2193
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
0 commit comments