@@ -73,10 +73,6 @@ pub(crate) fn init(context: &Context) {
7373}
7474
7575impl PyByteArray {
76- pub fn new_ref ( data : Vec < u8 > , ctx : & Context ) -> PyRef < Self > {
77- PyRef :: new_ref ( Self :: from ( data) , ctx. types . bytearray_type . to_owned ( ) , None )
78- }
79-
8076 fn from_inner ( inner : PyBytesInner ) -> Self {
8177 PyByteArray {
8278 inner : PyRwLock :: new ( inner) ,
@@ -134,7 +130,7 @@ impl PyByteArray {
134130 SequenceIndex :: Slice ( slice) => self
135131 . borrow_buf ( )
136132 . getitem_by_slice ( vm, slice)
137- . map ( |x| Self :: new_ref ( x , & vm. ctx ) . into ( ) ) ,
133+ . map ( |x| vm. ctx . new_bytearray ( x ) . into ( ) ) ,
138134 }
139135 }
140136
@@ -463,11 +459,8 @@ impl PyByteArray {
463459 options : ByteInnerSplitOptions ,
464460 vm : & VirtualMachine ,
465461 ) -> PyResult < Vec < PyObjectRef > > {
466- self . inner ( ) . split (
467- options,
468- |s, vm| Self :: new_ref ( s. to_vec ( ) , & vm. ctx ) . into ( ) ,
469- vm,
470- )
462+ self . inner ( )
463+ . split ( options, |s, vm| vm. ctx . new_bytearray ( s. to_vec ( ) ) . into ( ) , vm)
471464 }
472465
473466 #[ pymethod]
@@ -476,11 +469,8 @@ impl PyByteArray {
476469 options : ByteInnerSplitOptions ,
477470 vm : & VirtualMachine ,
478471 ) -> PyResult < Vec < PyObjectRef > > {
479- self . inner ( ) . rsplit (
480- options,
481- |s, vm| Self :: new_ref ( s. to_vec ( ) , & vm. ctx ) . into ( ) ,
482- vm,
483- )
472+ self . inner ( )
473+ . rsplit ( options, |s, vm| vm. ctx . new_bytearray ( s. to_vec ( ) ) . into ( ) , vm)
484474 }
485475
486476 #[ pymethod]
@@ -490,9 +480,10 @@ impl PyByteArray {
490480 let value = self . inner ( ) ;
491481 let ( front, has_mid, back) = value. partition ( & sep, vm) ?;
492482 Ok ( vm. new_tuple ( (
493- Self :: new_ref ( front. to_vec ( ) , & vm. ctx ) ,
494- Self :: new_ref ( if has_mid { sep. elements } else { Vec :: new ( ) } , & vm. ctx ) ,
495- Self :: new_ref ( back. to_vec ( ) , & vm. ctx ) ,
483+ vm. ctx . new_bytearray ( front. to_vec ( ) ) ,
484+ vm. ctx
485+ . new_bytearray ( if has_mid { sep. elements } else { Vec :: new ( ) } ) ,
486+ vm. ctx . new_bytearray ( back. to_vec ( ) ) ,
496487 ) ) )
497488 }
498489
@@ -501,9 +492,10 @@ impl PyByteArray {
501492 let value = self . inner ( ) ;
502493 let ( back, has_mid, front) = value. rpartition ( & sep, vm) ?;
503494 Ok ( vm. new_tuple ( (
504- Self :: new_ref ( front. to_vec ( ) , & vm. ctx ) ,
505- Self :: new_ref ( if has_mid { sep. elements } else { Vec :: new ( ) } , & vm. ctx ) ,
506- Self :: new_ref ( back. to_vec ( ) , & vm. ctx ) ,
495+ vm. ctx . new_bytearray ( front. to_vec ( ) ) ,
496+ vm. ctx
497+ . new_bytearray ( if has_mid { sep. elements } else { Vec :: new ( ) } ) ,
498+ vm. ctx . new_bytearray ( back. to_vec ( ) ) ,
507499 ) ) )
508500 }
509501
@@ -515,7 +507,7 @@ impl PyByteArray {
515507 #[ pymethod]
516508 fn splitlines ( & self , options : anystr:: SplitLinesArgs , vm : & VirtualMachine ) -> Vec < PyObjectRef > {
517509 self . inner ( )
518- . splitlines ( options, |x| Self :: new_ref ( x. to_vec ( ) , & vm . ctx ) . into ( ) )
510+ . splitlines ( options, |x| vm . ctx . new_bytearray ( x. to_vec ( ) ) . into ( ) )
519511 }
520512
521513 #[ pymethod]
@@ -873,10 +865,6 @@ impl Representable for PyByteArray {
873865 }
874866}
875867
876- // fn set_value(obj: &PyObject, value: Vec<u8>) {
877- // obj.borrow_mut().kind = PyObjectPayload::Bytes { value };
878- // }
879-
880868#[ pyclass( module = false , name = "bytearray_iterator" ) ]
881869#[ derive( Debug ) ]
882870pub struct PyByteArrayIterator {
0 commit comments