@@ -56,6 +56,8 @@ pub struct PyContext {
56
56
pub float_type : PyObjectRef ,
57
57
pub bytes_type : PyObjectRef ,
58
58
pub bool_type : PyObjectRef ,
59
+ pub true_value : PyObjectRef ,
60
+ pub false_value : PyObjectRef ,
59
61
pub list_type : PyObjectRef ,
60
62
pub tuple_type : PyObjectRef ,
61
63
pub str_type : PyObjectRef ,
@@ -127,12 +129,16 @@ impl PyContext {
127
129
create_type ( "NoneType" , & type_type, & object_type, & dict_type) ,
128
130
) ;
129
131
132
+ let true_value = PyObject :: new ( PyObjectKind :: Integer { value : 1 } , bool_type. clone ( ) ) ;
133
+ let false_value = PyObject :: new ( PyObjectKind :: Integer { value : 0 } , bool_type. clone ( ) ) ;
130
134
let context = PyContext {
131
135
int_type : int_type,
132
136
float_type : float_type,
133
137
bytes_type : bytes_type,
134
138
list_type : list_type,
135
139
bool_type : bool_type,
140
+ true_value : true_value,
141
+ false_value : false_value,
136
142
tuple_type : tuple_type,
137
143
dict_type : dict_type,
138
144
none : none,
@@ -220,12 +226,11 @@ impl PyContext {
220
226
}
221
227
222
228
pub fn new_bool ( & self , b : bool ) -> PyObjectRef {
223
- PyObject :: new (
224
- PyObjectKind :: Integer {
225
- value : if b { 1 } else { 0 } ,
226
- } ,
227
- self . bool_type ( ) ,
228
- )
229
+ if b {
230
+ self . true_value . clone ( )
231
+ } else {
232
+ self . false_value . clone ( )
233
+ }
229
234
}
230
235
231
236
pub fn new_tuple ( & self , elements : Vec < PyObjectRef > ) -> PyObjectRef {
0 commit comments