@@ -10,7 +10,7 @@ use crate::common::{
10
10
use crate :: {
11
11
builtins:: { PyInt , PyStr , PyStrRef } ,
12
12
convert:: ToPyObject ,
13
- AsObject , Py , PyObject , PyObjectRef , PyRefExact , PyResult , VirtualMachine ,
13
+ AsObject , Py , PyExact , PyObject , PyObjectRef , PyRefExact , PyResult , VirtualMachine ,
14
14
} ;
15
15
use num_traits:: ToPrimitive ;
16
16
use std:: { fmt, mem:: size_of, ops:: ControlFlow } ;
@@ -686,39 +686,39 @@ pub trait DictKey {
686
686
/// to index dictionaries.
687
687
impl DictKey for PyObject {
688
688
type Owned = PyObjectRef ;
689
- #[ inline]
689
+ #[ inline( always ) ]
690
690
fn _to_owned ( & self , _vm : & VirtualMachine ) -> Self :: Owned {
691
691
self . to_owned ( )
692
692
}
693
-
693
+ # [ inline ( always ) ]
694
694
fn key_hash ( & self , vm : & VirtualMachine ) -> PyResult < HashValue > {
695
695
self . hash ( vm)
696
696
}
697
-
697
+ # [ inline ( always ) ]
698
698
fn key_is ( & self , other : & PyObject ) -> bool {
699
699
self . is ( other)
700
700
}
701
-
701
+ # [ inline ( always ) ]
702
702
fn key_eq ( & self , vm : & VirtualMachine , other_key : & PyObject ) -> PyResult < bool > {
703
703
vm. identical_or_equal ( self , other_key)
704
704
}
705
-
705
+ # [ inline ]
706
706
fn key_as_isize ( & self , vm : & VirtualMachine ) -> PyResult < isize > {
707
707
vm. to_index ( self ) ?. try_to_primitive ( vm)
708
708
}
709
709
}
710
710
711
711
impl DictKey for Py < PyStr > {
712
712
type Owned = PyStrRef ;
713
- #[ inline]
713
+ #[ inline( always ) ]
714
714
fn _to_owned ( & self , _vm : & VirtualMachine ) -> Self :: Owned {
715
715
self . to_owned ( )
716
716
}
717
-
717
+ # [ inline ]
718
718
fn key_hash ( & self , vm : & VirtualMachine ) -> PyResult < HashValue > {
719
719
Ok ( self . hash ( vm) )
720
720
}
721
-
721
+ # [ inline ( always ) ]
722
722
fn key_is ( & self , other : & PyObject ) -> bool {
723
723
self . is ( other)
724
724
}
@@ -732,28 +732,31 @@ impl DictKey for Py<PyStr> {
732
732
vm. bool_eq ( self . as_object ( ) , other_key)
733
733
}
734
734
}
735
-
735
+ # [ inline ( always ) ]
736
736
fn key_as_isize ( & self , vm : & VirtualMachine ) -> PyResult < isize > {
737
737
self . as_object ( ) . key_as_isize ( vm)
738
738
}
739
739
}
740
740
741
- impl DictKey for PyRefExact < PyStr > {
742
- type Owned = Self ;
743
- #[ inline]
741
+ impl DictKey for PyExact < PyStr > {
742
+ type Owned = PyRefExact < PyStr > ;
743
+ #[ inline( always ) ]
744
744
fn _to_owned ( & self , _vm : & VirtualMachine ) -> Self :: Owned {
745
- self . clone ( )
745
+ self . to_owned ( )
746
746
}
747
-
747
+ # [ inline ( always ) ]
748
748
fn key_hash ( & self , vm : & VirtualMachine ) -> PyResult < HashValue > {
749
749
( * * self ) . key_hash ( vm)
750
750
}
751
+ #[ inline]
751
752
fn key_is ( & self , other : & PyObject ) -> bool {
752
753
( * * self ) . key_is ( other)
753
754
}
755
+ #[ inline( always) ]
754
756
fn key_eq ( & self , vm : & VirtualMachine , other_key : & PyObject ) -> PyResult < bool > {
755
757
( * * self ) . key_eq ( vm, other_key)
756
758
}
759
+ #[ inline( always) ]
757
760
fn key_as_isize ( & self , vm : & VirtualMachine ) -> PyResult < isize > {
758
761
( * * self ) . key_as_isize ( vm)
759
762
}
@@ -765,16 +768,16 @@ impl DictKey for PyRefExact<PyStr> {
765
768
/// to index dictionaries.
766
769
impl DictKey for str {
767
770
type Owned = String ;
768
- #[ inline]
771
+ #[ inline( always ) ]
769
772
fn _to_owned ( & self , _vm : & VirtualMachine ) -> Self :: Owned {
770
773
self . to_owned ( )
771
774
}
772
-
775
+ # [ inline ]
773
776
fn key_hash ( & self , vm : & VirtualMachine ) -> PyResult < HashValue > {
774
777
// follow a similar route as the hashing of PyStrRef
775
778
Ok ( vm. state . hash_secret . hash_str ( self ) )
776
779
}
777
-
780
+ # [ inline ( always ) ]
778
781
fn key_is ( & self , _other : & PyObject ) -> bool {
779
782
// No matter who the other pyobject is, we are never the same thing, since
780
783
// we are a str, not a pyobject.
0 commit comments