From: Robert Bradshaw Date: Thu, 9 Oct 2008 19:54:36 +0000 (-0700) Subject: Optimize conditions when one side of binop is pure C. X-Git-Tag: 0.9.9.2.beta~49 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=92a052ebd7b3a7aaab56af56ea0c55f3f6fdaf02;p=cython.git Optimize conditions when one side of binop is pure C. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 64668c99..939a15a3 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -746,6 +746,10 @@ class IntNode(ConstNode): # result, because we might be coercing to an extension type, # in which case a type test node will be needed. 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): if self.type.is_pyobject: @@ -3780,6 +3784,12 @@ class BoolBinopNode(ExprNode): else: return self.operand1.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): self.operand1.analyse_types(env) @@ -4397,6 +4407,9 @@ class CoerceToPyTypeNode(CoercionNode): "Cannot convert '%s' to Python object" % arg.type) gil_message = "Converting to Python object" + + def coerce_to_boolean(self, env): + return self.arg.coerce_to_boolean(env) def analyse_types(self, env): # The arg is always already analysed @@ -4491,6 +4504,12 @@ class CoerceToTempNode(CoercionNode): def analyse_types(self, env): # The arg is always already analysed 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): #self.arg.generate_evaluation_code(code) # Already done