Optimize bool by starting as bint rather than object.
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 23 Jul 2008 07:13:19 +0000 (00:13 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 23 Jul 2008 07:13:19 +0000 (00:13 -0700)
Cython/Compiler/ExprNodes.py

index 3ce905c801644d48df68600b66f127829b2ff396..992d922c8266ccc77adfb72b7ed50157e5152df9 100644 (file)
@@ -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"