320
320
#ifndef RectImport_RectCheckExact
321
321
#error RectImport_RectCheckExact needs to be Defined
322
322
#endif
323
+ #ifndef RectImport_OtherRectCheckExact
324
+ #error RectImport_OtherRectCheckExact needs to be Defined
325
+ #endif
323
326
#ifndef RectImport_primitiveType
324
327
#error RectImport_primitiveType needs to be defined
325
328
#endif
@@ -424,7 +427,7 @@ RectExport_do_rects_intresect(InnerRect *A, InnerRect *B)
424
427
425
428
#define _pg_do_rects_intersect RectExport_do_rects_intresect
426
429
427
- static InnerRect *
430
+ static PG_INLINE InnerRect *
428
431
RectExport_RectFromObject (PyObject * obj , InnerRect * temp );
429
432
static InnerRect *
430
433
RectExport_RectFromFastcallArgs (PyObject * const * args , Py_ssize_t nargs ,
@@ -611,16 +614,16 @@ static RectObject
611
614
int RectOptional_Freelist_Num = -1 ;
612
615
#endif
613
616
614
- static InnerRect *
617
+ static PG_INLINE InnerRect *
615
618
RectExport_RectFromObject (PyObject * obj , InnerRect * temp )
616
619
{
617
620
Py_ssize_t length ;
618
621
619
- if (RectCheck (obj )) {
622
+ /* fast path for exact Rect / FRect class */
623
+ if (RectImport_RectCheckExact (obj )) {
620
624
return & ((RectObject * )obj )-> r ;
621
625
}
622
-
623
- if (OtherRectCheck (obj )) {
626
+ if (RectImport_OtherRectCheckExact (obj )) {
624
627
OtherInnerRect rect = ((OtherRectObject * )obj )-> r ;
625
628
temp -> x = (PrimitiveType )rect .x ;
626
629
temp -> y = (PrimitiveType )rect .y ;
@@ -629,6 +632,7 @@ RectExport_RectFromObject(PyObject *obj, InnerRect *temp)
629
632
return temp ;
630
633
}
631
634
635
+ /* fast check for sequences */
632
636
if (pgSequenceFast_Check (obj )) {
633
637
length = PySequence_Fast_GET_SIZE (obj );
634
638
PyObject * * items = PySequence_Fast_ITEMS (obj );
@@ -721,7 +725,20 @@ RectExport_RectFromObject(PyObject *obj, InnerRect *temp)
721
725
}
722
726
}
723
727
724
- /* Try to get the rect attribute */
728
+ /* path for possible subclasses (these are very slow checks) */
729
+ if (RectImport_RectCheck (obj )) {
730
+ return & ((RectObject * )obj )-> r ;
731
+ }
732
+ if (RectImport_OtherRectCheck (obj )) {
733
+ OtherInnerRect rect = ((OtherRectObject * )obj )-> r ;
734
+ temp -> x = (PrimitiveType )rect .x ;
735
+ temp -> y = (PrimitiveType )rect .y ;
736
+ temp -> w = (PrimitiveType )rect .w ;
737
+ temp -> h = (PrimitiveType )rect .h ;
738
+ return temp ;
739
+ }
740
+
741
+ /* path to get the 'rect' attribute if present */
725
742
PyObject * rectattr ;
726
743
if (!(rectattr = PyObject_GetAttrString (obj , "rect" ))) {
727
744
PyErr_Clear ();
@@ -2933,6 +2950,7 @@ RectExport_iterator(RectObject *self)
2933
2950
#undef RectImport_RectCheck
2934
2951
#undef RectImport_OtherRectCheck
2935
2952
#undef RectImport_RectCheckExact
2953
+ #undef RectImport_OtherRectCheckExact
2936
2954
#undef RectImport_innerRectStruct
2937
2955
#undef RectImport_otherInnerRectStruct
2938
2956
#undef RectImport_innerPointStruct
0 commit comments