@@ -787,7 +787,11 @@ where
787
787
K : Borrow < Q > ,
788
788
Q : Hash + Eq ,
789
789
{
790
- self . get_key_value ( k) . map ( |( _, v) | v)
790
+ // Avoid `Option::map` because it bloats LLVM IR.
791
+ match self . get_key_value ( k) {
792
+ Some ( ( _, v) ) => Some ( v) ,
793
+ None => None ,
794
+ }
791
795
}
792
796
793
797
/// Returns the key-value pair corresponding to the supplied key.
@@ -816,12 +820,14 @@ where
816
820
Q : Hash + Eq ,
817
821
{
818
822
let hash = make_hash ( & self . hash_builder , k) ;
819
- self . table
820
- . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) )
821
- . map ( | item| unsafe {
823
+ // Avoid `Option::map` because it bloats LLVM IR.
824
+ match self . table . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) ) {
825
+ Some ( item) => unsafe {
822
826
let & ( ref key, ref value) = item. as_ref ( ) ;
823
- ( key, value)
824
- } )
827
+ Some ( ( key, value) )
828
+ } ,
829
+ None => None ,
830
+ }
825
831
}
826
832
827
833
/// Returns the key-value pair corresponding to the supplied key, with a mutable reference to value.
@@ -854,12 +860,14 @@ where
854
860
Q : Hash + Eq ,
855
861
{
856
862
let hash = make_hash ( & self . hash_builder , k) ;
857
- self . table
858
- . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) )
859
- . map ( | item| unsafe {
863
+ // Avoid `Option::map` because it bloats LLVM IR.
864
+ match self . table . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) ) {
865
+ Some ( item) => unsafe {
860
866
let & mut ( ref key, ref mut value) = item. as_mut ( ) ;
861
- ( key, value)
862
- } )
867
+ Some ( ( key, value) )
868
+ } ,
869
+ None => None ,
870
+ }
863
871
}
864
872
865
873
/// Returns `true` if the map contains a value for the specified key.
@@ -918,9 +926,11 @@ where
918
926
Q : Hash + Eq ,
919
927
{
920
928
let hash = make_hash ( & self . hash_builder , k) ;
921
- self . table
922
- . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) )
923
- . map ( |item| unsafe { & mut item. as_mut ( ) . 1 } )
929
+ // Avoid `Option::map` because it bloats LLVM IR.
930
+ match self . table . find ( hash, |x| k. eq ( x. 0 . borrow ( ) ) ) {
931
+ Some ( item) => Some ( unsafe { & mut item. as_mut ( ) . 1 } ) ,
932
+ None => None ,
933
+ }
924
934
}
925
935
926
936
/// Inserts a key-value pair into the map.
@@ -995,7 +1005,11 @@ where
995
1005
K : Borrow < Q > ,
996
1006
Q : Hash + Eq ,
997
1007
{
998
- self . remove_entry ( k) . map ( |( _, v) | v)
1008
+ // Avoid `Option::map` because it bloats LLVM IR.
1009
+ match self . remove_entry ( k) {
1010
+ Some ( ( _, v) ) => Some ( v) ,
1011
+ None => None ,
1012
+ }
999
1013
}
1000
1014
1001
1015
/// Removes a key from the map, returning the stored key and value if the
@@ -1478,13 +1492,13 @@ impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
1478
1492
where
1479
1493
F : FnMut ( & K ) -> bool ,
1480
1494
{
1481
- self . map
1482
- . table
1483
- . find ( hash, |( k, _) | is_match ( k) )
1484
- . map ( |item| unsafe {
1495
+ match self . map . table . find ( hash, |( k, _) | is_match ( k) ) {
1496
+ Some ( item) => unsafe {
1485
1497
let & ( ref key, ref value) = item. as_ref ( ) ;
1486
- ( key, value)
1487
- } )
1498
+ Some ( ( key, value) )
1499
+ } ,
1500
+ None => None ,
1501
+ }
1488
1502
}
1489
1503
1490
1504
/// Access an entry by hash.
@@ -1947,10 +1961,14 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
1947
1961
1948
1962
#[ cfg_attr( feature = "inline-more" , inline) ]
1949
1963
fn next ( & mut self ) -> Option < ( & ' a K , & ' a V ) > {
1950
- self . inner . next ( ) . map ( |x| unsafe {
1951
- let r = x. as_ref ( ) ;
1952
- ( & r. 0 , & r. 1 )
1953
- } )
1964
+ // Avoid `Option::map` because it bloats LLVM IR.
1965
+ match self . inner . next ( ) {
1966
+ Some ( x) => unsafe {
1967
+ let r = x. as_ref ( ) ;
1968
+ Some ( ( & r. 0 , & r. 1 ) )
1969
+ } ,
1970
+ None => None ,
1971
+ }
1954
1972
}
1955
1973
#[ cfg_attr( feature = "inline-more" , inline) ]
1956
1974
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -1971,10 +1989,14 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
1971
1989
1972
1990
#[ cfg_attr( feature = "inline-more" , inline) ]
1973
1991
fn next ( & mut self ) -> Option < ( & ' a K , & ' a mut V ) > {
1974
- self . inner . next ( ) . map ( |x| unsafe {
1975
- let r = x. as_mut ( ) ;
1976
- ( & r. 0 , & mut r. 1 )
1977
- } )
1992
+ // Avoid `Option::map` because it bloats LLVM IR.
1993
+ match self . inner . next ( ) {
1994
+ Some ( x) => unsafe {
1995
+ let r = x. as_mut ( ) ;
1996
+ Some ( ( & r. 0 , & mut r. 1 ) )
1997
+ } ,
1998
+ None => None ,
1999
+ }
1978
2000
}
1979
2001
#[ cfg_attr( feature = "inline-more" , inline) ]
1980
2002
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -2030,7 +2052,11 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
2030
2052
2031
2053
#[ cfg_attr( feature = "inline-more" , inline) ]
2032
2054
fn next ( & mut self ) -> Option < & ' a K > {
2033
- self . inner . next ( ) . map ( |( k, _) | k)
2055
+ // Avoid `Option::map` because it bloats LLVM IR.
2056
+ match self . inner . next ( ) {
2057
+ Some ( ( k, _) ) => Some ( k) ,
2058
+ None => None ,
2059
+ }
2034
2060
}
2035
2061
#[ cfg_attr( feature = "inline-more" , inline) ]
2036
2062
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -2050,7 +2076,11 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
2050
2076
2051
2077
#[ cfg_attr( feature = "inline-more" , inline) ]
2052
2078
fn next ( & mut self ) -> Option < & ' a V > {
2053
- self . inner . next ( ) . map ( |( _, v) | v)
2079
+ // Avoid `Option::map` because it bloats LLVM IR.
2080
+ match self . inner . next ( ) {
2081
+ Some ( ( _, v) ) => Some ( v) ,
2082
+ None => None ,
2083
+ }
2054
2084
}
2055
2085
#[ cfg_attr( feature = "inline-more" , inline) ]
2056
2086
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
@@ -2070,7 +2100,11 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
2070
2100
2071
2101
#[ cfg_attr( feature = "inline-more" , inline) ]
2072
2102
fn next ( & mut self ) -> Option < & ' a mut V > {
2073
- self . inner . next ( ) . map ( |( _, v) | v)
2103
+ // Avoid `Option::map` because it bloats LLVM IR.
2104
+ match self . inner . next ( ) {
2105
+ Some ( ( _, v) ) => Some ( v) ,
2106
+ None => None ,
2107
+ }
2074
2108
}
2075
2109
#[ cfg_attr( feature = "inline-more" , inline) ]
2076
2110
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
0 commit comments