Skip to content

Commit 15da3e6

Browse files
committed
optimize _UNARY_NEGATIVE
1 parent a380d57 commit 15da3e6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Python/optimizer_bytecodes.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,15 @@ dummy_func(void) {
467467
res = sym_new_truthiness(ctx, value, false);
468468
}
469469

470+
op(_UNARY_NEGATIVE, (value -- res)) {
471+
if (sym_matches_type(value, &PyLong_Type) || sym_matches_type(value, &PyFloat_Type)) {
472+
res = sym_new_type(ctx, sym_get_type(value));
473+
}
474+
else {
475+
res = sym_new_not_null(ctx);
476+
}
477+
}
478+
470479
op(_COMPARE_OP, (left, right -- res)) {
471480
if (oparg & 16) {
472481
res = sym_new_type(ctx, &PyBool_Type);

Python/optimizer_cases.c.h

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)