summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index 5d339b8..b1f9eb7 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -600,6 +600,12 @@ _PyCode_Quicken(PyCodeObject *code)
#define SPEC_FAIL_TO_BOOL_SET 17
#define SPEC_FAIL_TO_BOOL_TUPLE 18
+// CONTAINS_OP
+#define SPEC_FAIL_CONTAINS_OP_STR 9
+#define SPEC_FAIL_CONTAINS_OP_TUPLE 10
+#define SPEC_FAIL_CONTAINS_OP_LIST 11
+#define SPEC_FAIL_CONTAINS_OP_USER_CLASS 12
+
static int function_kind(PyCodeObject *code);
static bool function_check_args(PyObject *o, int expected_argcount, int opcode);
static uint32_t function_get_version(PyObject *o, int opcode);
@@ -2562,34 +2568,40 @@ success:
cache->counter = adaptive_counter_cooldown();
}
-void
-_Py_Specialize_ContainsOp(PyObject *value, _Py_CODEUNIT *instr)
-{
- assert(ENABLE_SPECIALIZATION);
- assert(_PyOpcode_Caches[CONTAINS_OP] == INLINE_CACHE_ENTRIES_COMPARE_OP);
- _PyContainsOpCache *cache = (_PyContainsOpCache *)(instr + 1);
+#ifdef Py_STATS
+static int containsop_fail_kind(PyObject *value) {
if (PyUnicode_CheckExact(value)) {
- instr->op.code = CONTAINS_OP_STR;
- goto success;
+ return SPEC_FAIL_CONTAINS_OP_STR;
}
if (PyList_CheckExact(value)) {
- instr->op.code = CONTAINS_OP_LIST;
- goto success;
+ return SPEC_FAIL_CONTAINS_OP_LIST;
}
if (PyTuple_CheckExact(value)) {
- instr->op.code = CONTAINS_OP_TUPLE;
- goto success;
+ return SPEC_FAIL_CONTAINS_OP_TUPLE;
+ }
+ if (PyType_Check(value)) {
+ return SPEC_FAIL_CONTAINS_OP_USER_CLASS;
}
+ return SPEC_FAIL_OTHER;
+}
+#endif // Py_STATS
+
+void
+_Py_Specialize_ContainsOp(PyObject *value, _Py_CODEUNIT *instr)
+{
+ assert(ENABLE_SPECIALIZATION);
+ assert(_PyOpcode_Caches[CONTAINS_OP] == INLINE_CACHE_ENTRIES_COMPARE_OP);
+ _PyContainsOpCache *cache = (_PyContainsOpCache *)(instr + 1);
if (PyDict_CheckExact(value)) {
instr->op.code = CONTAINS_OP_DICT;
goto success;
}
- if (PySet_CheckExact(value)) {
+ if (PySet_CheckExact(value) || PyFrozenSet_CheckExact(value)) {
instr->op.code = CONTAINS_OP_SET;
goto success;
}
-
+ SPECIALIZATION_FAIL(CONTAINS_OP, containsop_fail_kind(value));
STAT_INC(CONTAINS_OP, failure);
instr->op.code = CONTAINS_OP;
cache->counter = adaptive_counter_backoff(cache->counter);