From b150b6aca7b17efe1bb13c3058d61cdefb83237e Mon Sep 17 00:00:00 2001 From: Noam Cohen Date: Mon, 9 Jun 2025 13:33:18 +0300 Subject: gh-131798: Optimize `_UNARY_INVERT` (GH-135222) --- Python/optimizer_bytecodes.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Python/optimizer_bytecodes.c') diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index fbf4dfd3db6..a9d5e92ca02 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -467,6 +467,15 @@ dummy_func(void) { res = sym_new_truthiness(ctx, value, false); } + op(_UNARY_INVERT, (value -- res)) { + if (sym_matches_type(value, &PyLong_Type)) { + res = sym_new_type(ctx, &PyLong_Type); + } + else { + res = sym_new_not_null(ctx); + } + } + op(_COMPARE_OP, (left, right -- res)) { if (oparg & 16) { res = sym_new_type(ctx, &PyBool_Type); -- cgit v1.2.3