Commit 92a052eb authored by Robert Bradshaw's avatar Robert Bradshaw

Optimize conditions when one side of binop is pure C.

parent ff152fe9
...@@ -746,6 +746,10 @@ class IntNode(ConstNode): ...@@ -746,6 +746,10 @@ class IntNode(ConstNode):
# result, because we might be coercing to an extension type, # result, because we might be coercing to an extension type,
# in which case a type test node will be needed. # in which case a type test node will be needed.
return ConstNode.coerce_to(self, dst_type, env) return ConstNode.coerce_to(self, dst_type, env)
def coerce_to_boolean(self, env):
self.type = PyrexTypes.c_bint_type
return self
def calculate_result_code(self): def calculate_result_code(self):
if self.type.is_pyobject: if self.type.is_pyobject:
...@@ -3780,6 +3784,12 @@ class BoolBinopNode(ExprNode): ...@@ -3780,6 +3784,12 @@ class BoolBinopNode(ExprNode):
else: else:
return self.operand1.compile_time_value(denv) \ return self.operand1.compile_time_value(denv) \
or self.operand2.compile_time_value(denv) or self.operand2.compile_time_value(denv)
def coerce_to_boolean(self, env):
self.operand1 = self.operand1.coerce_to_boolean(env)
self.operand2 = self.operand2.coerce_to_boolean(env)
self.type = PyrexTypes.c_bint_type
return self
def analyse_types(self, env): def analyse_types(self, env):
self.operand1.analyse_types(env) self.operand1.analyse_types(env)
...@@ -4397,6 +4407,9 @@ class CoerceToPyTypeNode(CoercionNode): ...@@ -4397,6 +4407,9 @@ class CoerceToPyTypeNode(CoercionNode):
"Cannot convert '%s' to Python object" % arg.type) "Cannot convert '%s' to Python object" % arg.type)
gil_message = "Converting to Python object" gil_message = "Converting to Python object"
def coerce_to_boolean(self, env):
return self.arg.coerce_to_boolean(env)
def analyse_types(self, env): def analyse_types(self, env):
# The arg is always already analysed # The arg is always already analysed
...@@ -4491,6 +4504,12 @@ class CoerceToTempNode(CoercionNode): ...@@ -4491,6 +4504,12 @@ class CoerceToTempNode(CoercionNode):
def analyse_types(self, env): def analyse_types(self, env):
# The arg is always already analysed # The arg is always already analysed
pass pass
def coerce_to_boolean(self, env):
self.arg = self.arg.coerce_to_boolean(env)
self.type = self.arg.type
self.result_ctype = self.type
return self
def generate_result_code(self, code): def generate_result_code(self, code):
#self.arg.generate_evaluation_code(code) # Already done #self.arg.generate_evaluation_code(code) # Already done
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment