From fd9548af95670357c33d4285acc16f78fe42385b Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Thu, 26 Feb 2026 22:17:30 +0100 Subject: [PATCH] Fast path for MATCH_CLASS zero argument case --- Python/codegen.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Python/codegen.c b/Python/codegen.c index 5749b615386717..a63bcd367a9630 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -6103,6 +6103,11 @@ codegen_pattern_class(compiler *c, pattern_ty p, pattern_context *pc) } ADDOP_LOAD_CONST_NEW(c, LOC(p), attr_names); ADDOP_I(c, LOC(p), MATCH_CLASS, nargs); + if ((nargs + nattrs) == 0) { + RETURN_IF_ERROR(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE)); + // If there are no patterns, we're done! + return SUCCESS; + } ADDOP_I(c, LOC(p), COPY, 1); ADDOP_LOAD_CONST(c, LOC(p), Py_None); ADDOP_I(c, LOC(p), IS_OP, 1);