File tree 5 files changed +9
-4
lines changed
5 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ pub struct PyDowncastError<'a> {
53
53
impl < ' a > PyDowncastError < ' a > {
54
54
/// Create a new `PyDowncastError` representing a failure to convert the object
55
55
/// `from` into the type named in `to`.
56
+ #[ cold]
56
57
pub fn new ( from : & ' a PyAny , to : impl Into < Cow < ' static , str > > ) -> Self {
57
58
PyDowncastError {
58
59
from,
Original file line number Diff line number Diff line change @@ -847,6 +847,7 @@ impl PyAny {
847
847
/// Extracts some type from the Python object.
848
848
///
849
849
/// This is a wrapper function around [`FromPyObject::extract()`].
850
+ #[ inline]
850
851
pub fn extract < ' a , D > ( & ' a self ) -> PyResult < D >
851
852
where
852
853
D : FromPyObject < ' a > ,
Original file line number Diff line number Diff line change @@ -123,7 +123,10 @@ fn get_mapping_abc(py: Python<'_>) -> PyResult<&PyType> {
123
123
impl PyTypeCheck for PyMapping {
124
124
const NAME : & ' static str = "Mapping" ;
125
125
126
+ #[ inline]
126
127
fn type_check ( object : & PyAny ) -> bool {
128
+ // Using `is_instance` for `collections.abc.Mapping` is slow, so provide
129
+ // optimized case dict as a well-known mapping
127
130
PyDict :: is_type_of ( object)
128
131
|| get_mapping_abc ( object. py ( ) )
129
132
. and_then ( |abc| object. is_instance ( abc) )
@@ -139,8 +142,6 @@ impl<'v> crate::PyTryFrom<'v> for PyMapping {
139
142
fn try_from < V : Into < & ' v PyAny > > ( value : V ) -> Result < & ' v PyMapping , PyDowncastError < ' v > > {
140
143
let value = value. into ( ) ;
141
144
142
- // Using `is_instance` for `collections.abc.Mapping` is slow, so provide
143
- // optimized case dict as a well-known mapping
144
145
if PyMapping :: type_check ( value) {
145
146
unsafe { return Ok ( value. downcast_unchecked ( ) ) }
146
147
}
Original file line number Diff line number Diff line change @@ -219,6 +219,7 @@ macro_rules! pyobject_native_type_info(
219
219
macro_rules! pyobject_native_type_extract {
220
220
( $name: ty $( ; $generics: ident) * ) => {
221
221
impl <' py, $( $generics, ) * > $crate:: FromPyObject <' py> for & ' py $name {
222
+ #[ inline]
222
223
fn extract( obj: & ' py $crate:: PyAny ) -> $crate:: PyResult <Self > {
223
224
obj. downcast( ) . map_err( :: std:: convert:: Into :: into)
224
225
}
Original file line number Diff line number Diff line change @@ -327,7 +327,10 @@ fn get_sequence_abc(py: Python<'_>) -> PyResult<&PyType> {
327
327
impl PyTypeCheck for PySequence {
328
328
const NAME : & ' static str = "Sequence" ;
329
329
330
+ #[ inline]
330
331
fn type_check ( object : & PyAny ) -> bool {
332
+ // Using `is_instance` for `collections.abc.Sequence` is slow, so provide
333
+ // optimized cases for list and tuples as common well-known sequences
331
334
PyList :: is_type_of ( object)
332
335
|| PyTuple :: is_type_of ( object)
333
336
|| get_sequence_abc ( object. py ( ) )
@@ -344,8 +347,6 @@ impl<'v> crate::PyTryFrom<'v> for PySequence {
344
347
fn try_from < V : Into < & ' v PyAny > > ( value : V ) -> Result < & ' v PySequence , PyDowncastError < ' v > > {
345
348
let value = value. into ( ) ;
346
349
347
- // Using `is_instance` for `collections.abc.Sequence` is slow, so provide
348
- // optimized cases for list and tuples as common well-known sequences
349
350
if PySequence :: type_check ( value) {
350
351
unsafe { return Ok ( value. downcast_unchecked :: < PySequence > ( ) ) }
351
352
}
You can’t perform that action at this time.
0 commit comments