From 8958817ff5ca8ebc898296b7f02957a3662a3b64 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 23 Jul 2008 00:13:19 -0700 Subject: [PATCH] Optimize bool by starting as bint rather than object. --- Cython/Compiler/ExprNodes.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 3ce905c8..992d922c 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -588,25 +588,6 @@ class NoneNode(PyConstNode): def compile_time_value(self, denv): return None -class BoolNode(PyConstNode): - # The constant value True or False - - def compile_time_value(self, denv): - return self.value - - def calculate_result_code(self): - if self.value: - return "Py_True" - else: - return "Py_False" - - def coerce_to(self, dst_type, env): - value = self.value - if dst_type.is_numeric: - return IntNode(self.pos, value=int(self.value)).coerce_to(dst_type, env) - else: - return PyConstNode.coerce_to(self, dst_type, env) - class EllipsisNode(PyConstNode): # '...' in a subscript list. @@ -639,6 +620,16 @@ class ConstNode(AtomicExprNode): pass +class BoolNode(ConstNode): + type = PyrexTypes.c_bint_type + # The constant value True or False + + def compile_time_value(self, denv): + return self.value + + def calculate_result_code(self): + return int(self.value) + class NullNode(ConstNode): type = PyrexTypes.c_null_ptr_type value = "NULL" -- 2.26.2