]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126513: Use helpers for `_Py_Specialize_ConstainsOp` (#126517)
authorKirill Podoprigora <kirill.bast9@mail.ru>
Wed, 6 Nov 2024 21:52:15 +0000 (23:52 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Nov 2024 21:52:15 +0000 (13:52 -0800)
* Use helpers for _Py_Specialize_ConstainsOp

* Remove unnecessary variable

Python/specialize.c

index 2673e16e596a1a13ee81064b9347a03ecf3a8ea0..0699e7be5e6b9c4c406b334f6352e6c696437d20 100644 (file)
@@ -2760,8 +2760,8 @@ success:
     cache->counter = adaptive_counter_cooldown();
 }
 
-#ifdef Py_STATS
-static int containsop_fail_kind(PyObject *value) {
+static int
+containsop_fail_kind(PyObject *value) {
     if (PyUnicode_CheckExact(value)) {
         return SPEC_FAIL_CONTAINS_OP_STR;
     }
@@ -2776,7 +2776,6 @@ static int containsop_fail_kind(PyObject *value) {
     }
     return SPEC_FAIL_OTHER;
 }
-#endif   // Py_STATS
 
 void
 _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
@@ -2785,26 +2784,17 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
 
     assert(ENABLE_SPECIALIZATION_FT);
     assert(_PyOpcode_Caches[CONTAINS_OP] == INLINE_CACHE_ENTRIES_COMPARE_OP);
-    uint8_t specialized_op;
-    _PyContainsOpCache *cache = (_PyContainsOpCache  *)(instr + 1);
     if (PyDict_CheckExact(value)) {
-        specialized_op = CONTAINS_OP_DICT;
-        goto success;
+        specialize(instr, CONTAINS_OP_DICT);
+        return;
     }
     if (PySet_CheckExact(value) || PyFrozenSet_CheckExact(value)) {
-        specialized_op = CONTAINS_OP_SET;
-        goto success;
+        specialize(instr, CONTAINS_OP_SET);
+        return;
     }
 
-    SPECIALIZATION_FAIL(CONTAINS_OP, containsop_fail_kind(value));
-    STAT_INC(CONTAINS_OP, failure);
-    SET_OPCODE_OR_RETURN(instr, CONTAINS_OP);
-    cache->counter = adaptive_counter_backoff(cache->counter);
+    unspecialize(instr, containsop_fail_kind(value));
     return;
-success:
-    STAT_INC(CONTAINS_OP, success);
-    SET_OPCODE_OR_RETURN(instr, specialized_op);
-    cache->counter = adaptive_counter_cooldown();
 }
 
 /* Code init cleanup.