@@ -1814,112 +1814,110 @@ _Py_Specialize_BinarySubscr(
1814
1814
cache -> counter = adaptive_counter_cooldown ();
1815
1815
}
1816
1816
1817
- void
1818
- _Py_Specialize_StoreSubscr (_PyStackRef container_st , _PyStackRef sub_st , _Py_CODEUNIT * instr )
1819
- {
1820
- PyObject * container = PyStackRef_AsPyObjectBorrow (container_st );
1821
- PyObject * sub = PyStackRef_AsPyObjectBorrow (sub_st );
1822
1817
1823
- assert (ENABLE_SPECIALIZATION );
1824
- _PyStoreSubscrCache * cache = (_PyStoreSubscrCache * )(instr + 1 );
1825
- PyTypeObject * container_type = Py_TYPE (container );
1826
- if (container_type == & PyList_Type ) {
1827
- if (PyLong_CheckExact (sub )) {
1828
- if (_PyLong_IsNonNegativeCompact ((PyLongObject * )sub )
1829
- && ((PyLongObject * )sub )-> long_value .ob_digit [0 ] < (size_t )PyList_GET_SIZE (container ))
1830
- {
1831
- instr -> op .code = STORE_SUBSCR_LIST_INT ;
1832
- goto success ;
1833
- }
1834
- else {
1835
- SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_OUT_OF_RANGE );
1836
- goto fail ;
1837
- }
1838
- }
1839
- else if (PySlice_Check (sub )) {
1840
- SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_SUBSCR_LIST_SLICE );
1841
- goto fail ;
1842
- }
1843
- else {
1844
- SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_OTHER );
1845
- goto fail ;
1846
- }
1847
- }
1848
- if (container_type == & PyDict_Type ) {
1849
- instr -> op .code = STORE_SUBSCR_DICT ;
1850
- goto success ;
1851
- }
1852
1818
#ifdef Py_STATS
1819
+ static int
1820
+ store_subscr_fail_kind (PyObject * container_type )
1821
+ {
1853
1822
PyMappingMethods * as_mapping = container_type -> tp_as_mapping ;
1854
1823
if (as_mapping && (as_mapping -> mp_ass_subscript
1855
1824
== PyDict_Type .tp_as_mapping -> mp_ass_subscript )) {
1856
- SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_SUBSCR_DICT_SUBCLASS_NO_OVERRIDE );
1857
- goto fail ;
1825
+ return SPEC_FAIL_SUBSCR_DICT_SUBCLASS_NO_OVERRIDE ;
1858
1826
}
1859
1827
if (PyObject_CheckBuffer (container )) {
1860
1828
if (PyLong_CheckExact (sub ) && (!_PyLong_IsNonNegativeCompact ((PyLongObject * )sub ))) {
1861
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_OUT_OF_RANGE ) ;
1829
+ return SPEC_FAIL_OUT_OF_RANGE ;
1862
1830
}
1863
1831
else if (strcmp (container_type -> tp_name , "array.array" ) == 0 ) {
1864
1832
if (PyLong_CheckExact (sub )) {
1865
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_ARRAY_INT ) ;
1833
+ return SPEC_FAIL_SUBSCR_ARRAY_INT ;
1866
1834
}
1867
1835
else if (PySlice_Check (sub )) {
1868
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_ARRAY_SLICE ) ;
1836
+ return SPEC_FAIL_SUBSCR_ARRAY_SLICE ;
1869
1837
}
1870
1838
else {
1871
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_OTHER ) ;
1839
+ return SPEC_FAIL_OTHER ;
1872
1840
}
1873
1841
}
1874
1842
else if (PyByteArray_CheckExact (container )) {
1875
1843
if (PyLong_CheckExact (sub )) {
1876
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_BYTEARRAY_INT ) ;
1844
+ return SPEC_FAIL_SUBSCR_BYTEARRAY_INT ;
1877
1845
}
1878
1846
else if (PySlice_Check (sub )) {
1879
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_BYTEARRAY_SLICE ) ;
1847
+ return SPEC_FAIL_SUBSCR_BYTEARRAY_SLICE ;
1880
1848
}
1881
1849
else {
1882
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_OTHER ) ;
1850
+ return SPEC_FAIL_OTHER ;
1883
1851
}
1884
1852
}
1885
1853
else {
1886
1854
if (PyLong_CheckExact (sub )) {
1887
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_BUFFER_INT ) ;
1855
+ return SPEC_FAIL_SUBSCR_BUFFER_INT ;
1888
1856
}
1889
1857
else if (PySlice_Check (sub )) {
1890
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_BUFFER_SLICE ) ;
1858
+ return SPEC_FAIL_SUBSCR_BUFFER_SLICE ;
1891
1859
}
1892
1860
else {
1893
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_OTHER ) ;
1861
+ return SPEC_FAIL_OTHER ;
1894
1862
}
1895
1863
}
1896
- goto fail ;
1864
+ return SPEC_FAIL_OTHER ;
1897
1865
}
1898
1866
PyObject * descriptor = _PyType_Lookup (container_type , & _Py_ID (__setitem__ ));
1899
1867
if (descriptor && Py_TYPE (descriptor ) == & PyFunction_Type ) {
1900
1868
PyFunctionObject * func = (PyFunctionObject * )descriptor ;
1901
1869
PyCodeObject * code = (PyCodeObject * )func -> func_code ;
1902
1870
int kind = function_kind (code );
1903
1871
if (kind == SIMPLE_FUNCTION ) {
1904
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_PY_SIMPLE ) ;
1872
+ return SPEC_FAIL_SUBSCR_PY_SIMPLE ;
1905
1873
}
1906
1874
else {
1907
- SPECIALIZATION_FAIL ( STORE_SUBSCR , SPEC_FAIL_SUBSCR_PY_OTHER ) ;
1875
+ return SPEC_FAIL_SUBSCR_PY_OTHER ;
1908
1876
}
1909
- goto fail ;
1910
1877
}
1911
- #endif // Py_STATS
1912
- SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_OTHER );
1913
- fail :
1914
- STAT_INC (STORE_SUBSCR , failure );
1915
- assert (!PyErr_Occurred ());
1916
- instr -> op .code = STORE_SUBSCR ;
1917
- cache -> counter = adaptive_counter_backoff (cache -> counter );
1918
- return ;
1919
- success :
1920
- STAT_INC (STORE_SUBSCR , success );
1921
- assert (!PyErr_Occurred ());
1922
- cache -> counter = adaptive_counter_cooldown ();
1878
+ return SPEC_FAIL_OTHER ;
1879
+ }
1880
+ #endif
1881
+
1882
+ void
1883
+ _Py_Specialize_StoreSubscr (_PyStackRef container_st , _PyStackRef sub_st , _Py_CODEUNIT * instr )
1884
+ {
1885
+ PyObject * container = PyStackRef_AsPyObjectBorrow (container_st );
1886
+ PyObject * sub = PyStackRef_AsPyObjectBorrow (sub_st );
1887
+
1888
+ assert (ENABLE_SPECIALIZATION_FT );
1889
+ PyTypeObject * container_type = Py_TYPE (container );
1890
+ if (container_type == & PyList_Type ) {
1891
+ if (PyLong_CheckExact (sub )) {
1892
+ if (_PyLong_IsNonNegativeCompact ((PyLongObject * )sub )
1893
+ && ((PyLongObject * )sub )-> long_value .ob_digit [0 ] < (size_t )PyList_GET_SIZE (container ))
1894
+ {
1895
+ specialize (instr , STORE_SUBSCR_LIST_INT );
1896
+ return ;
1897
+ }
1898
+ else {
1899
+ SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_OUT_OF_RANGE );
1900
+ unspecialize (instr );
1901
+ return ;
1902
+ }
1903
+ }
1904
+ else if (PySlice_Check (sub )) {
1905
+ SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_SUBSCR_LIST_SLICE );
1906
+ unspecialize (instr );
1907
+ return ;
1908
+ }
1909
+ else {
1910
+ SPECIALIZATION_FAIL (STORE_SUBSCR , SPEC_FAIL_OTHER );
1911
+ unspecialize (instr );
1912
+ return ;
1913
+ }
1914
+ }
1915
+ if (container_type == & PyDict_Type ) {
1916
+ specialize (instr , STORE_SUBSCR_DICT );
1917
+ return ;
1918
+ }
1919
+ SPECIALIZATION_FAIL (STORE_SUBSCR , store_subscr_fail_kind (container_type ));
1920
+ unspecialize (instr );
1923
1921
}
1924
1922
1925
1923
/* Returns a borrowed reference.
0 commit comments