@@ -234,8 +234,8 @@ declare_const_name! {
234
234
235
235
// Basic objects:
236
236
impl Context {
237
- pub const INT_CACHE_POOL_MIN : i32 = - 5 ;
238
- pub const INT_CACHE_POOL_MAX : i32 = 256 ;
237
+ pub const INT_CACHE_POOL_RANGE : std :: ops :: RangeInclusive < i32 > = ( - 5 ) ..= 256 ;
238
+ const INT_CACHE_POOL_MIN : i32 = * Self :: INT_CACHE_POOL_RANGE . start ( ) ;
239
239
240
240
pub fn genesis ( ) -> & ' static PyRc < Self > {
241
241
rustpython_common:: static_cell! {
@@ -261,7 +261,7 @@ impl Context {
261
261
let ellipsis = create_object ( PyEllipsis , PyEllipsis :: static_type ( ) ) ;
262
262
let not_implemented = create_object ( PyNotImplemented , PyNotImplemented :: static_type ( ) ) ;
263
263
264
- let int_cache_pool = ( Self :: INT_CACHE_POOL_MIN ..= Self :: INT_CACHE_POOL_MAX )
264
+ let int_cache_pool = Self :: INT_CACHE_POOL_RANGE
265
265
. map ( |v| {
266
266
PyRef :: new_ref (
267
267
PyInt :: from ( BigInt :: from ( v) ) ,
@@ -358,37 +358,33 @@ impl Context {
358
358
#[ inline]
359
359
pub fn new_int < T : Into < BigInt > + ToPrimitive > ( & self , i : T ) -> PyIntRef {
360
360
if let Some ( i) = i. to_i32 ( ) {
361
- if ( Self :: INT_CACHE_POOL_MIN ..= Self :: INT_CACHE_POOL_MAX ) . contains ( & i) {
361
+ if Self :: INT_CACHE_POOL_RANGE . contains ( & i) {
362
362
let inner_idx = ( i - Self :: INT_CACHE_POOL_MIN ) as usize ;
363
363
return self . int_cache_pool [ inner_idx] . clone ( ) ;
364
364
}
365
365
}
366
- PyRef :: new_ref ( PyInt :: from ( i) , self . types . int_type . to_owned ( ) , None )
366
+ PyInt :: from ( i) . into_ref ( self )
367
367
}
368
368
369
369
#[ inline]
370
370
pub fn new_bigint ( & self , i : & BigInt ) -> PyIntRef {
371
371
if let Some ( i) = i. to_i32 ( ) {
372
- if ( Self :: INT_CACHE_POOL_MIN ..= Self :: INT_CACHE_POOL_MAX ) . contains ( & i) {
372
+ if Self :: INT_CACHE_POOL_RANGE . contains ( & i) {
373
373
let inner_idx = ( i - Self :: INT_CACHE_POOL_MIN ) as usize ;
374
374
return self . int_cache_pool [ inner_idx] . clone ( ) ;
375
375
}
376
376
}
377
- PyRef :: new_ref ( PyInt :: from ( i. clone ( ) ) , self . types . int_type . to_owned ( ) , None )
377
+ PyInt :: from ( i. clone ( ) ) . into_ref ( self )
378
378
}
379
379
380
380
#[ inline]
381
381
pub fn new_float ( & self , value : f64 ) -> PyRef < PyFloat > {
382
- PyRef :: new_ref ( PyFloat :: from ( value) , self . types . float_type . to_owned ( ) , None )
382
+ PyFloat :: from ( value) . into_ref ( self )
383
383
}
384
384
385
385
#[ inline]
386
386
pub fn new_complex ( & self , value : Complex64 ) -> PyRef < PyComplex > {
387
- PyRef :: new_ref (
388
- PyComplex :: from ( value) ,
389
- self . types . complex_type . to_owned ( ) ,
390
- None ,
391
- )
387
+ PyComplex :: from ( value) . into_ref ( self )
392
388
}
393
389
394
390
#[ inline]
0 commit comments