summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2020-04-01 12:38:09 +0200
committerStefan Behnel <stefan_ml@behnel.de>2020-04-01 12:38:09 +0200
commite2d1090fe6f0f67ecf860e218a42dfd257dc88a9 (patch)
tree7df5851dc8063c0e8c930a27874a0d59eef999e3
parent6e8c26e2bac199e45afa8e0559a5878e86ed4154 (diff)
downloadcython-e2d1090fe6f0f67ecf860e218a42dfd257dc88a9.tar.gz
Fix branch prediction hints for plain (unlikely/exceptional) "raise" statements in if/else clauses that are not preceded by other statements.
-rw-r--r--Cython/Compiler/Nodes.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index e79f4a6ef..2597f73c8 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -6515,14 +6515,18 @@ class IfStatNode(StatNode):
def _set_branch_hint(self, clause, statements_node, inverse=False):
if not statements_node.is_terminator:
return
- if not isinstance(statements_node, StatListNode) or not statements_node.stats:
- return
+ if isinstance(statements_node, StatListNode):
+ if not statements_node.stats:
+ return
+ statements = statements_node.stats
+ else:
+ statements = [statements_node]
# Anything that unconditionally raises exceptions should be considered unlikely.
- if isinstance(statements_node.stats[-1], (RaiseStatNode, ReraiseStatNode)):
- if len(statements_node.stats) > 1:
+ if isinstance(statements[-1], (RaiseStatNode, ReraiseStatNode)):
+ if len(statements) > 1:
# Allow simple statements before the 'raise', but no conditions, loops, etc.
non_branch_nodes = (ExprStatNode, AssignmentNode, DelStatNode, GlobalNode, NonlocalNode)
- for node in statements_node.stats[:-1]:
+ for node in statements[:-1]:
if not isinstance(node, non_branch_nodes):
return
clause.branch_hint = 'likely' if inverse else 'unlikely'