@@ -134,7 +134,7 @@ impl PyByteArray {
134134 SequenceIndex :: Slice ( slice) => self
135135 . borrow_buf ( )
136136 . getitem_by_slice ( vm, slice)
137- . map ( |x| Self :: new_ref ( x , & vm. ctx ) . into ( ) ) ,
137+ . map ( |x| vm. ctx . new_bytearray ( x ) . into ( ) ) ,
138138 }
139139 }
140140
@@ -463,11 +463,8 @@ impl PyByteArray {
463463 options : ByteInnerSplitOptions ,
464464 vm : & VirtualMachine ,
465465 ) -> PyResult < Vec < PyObjectRef > > {
466- self . inner ( ) . split (
467- options,
468- |s, vm| Self :: new_ref ( s. to_vec ( ) , & vm. ctx ) . into ( ) ,
469- vm,
470- )
466+ self . inner ( )
467+ . split ( options, |s, vm| vm. ctx . new_bytearray ( s. to_vec ( ) ) . into ( ) , vm)
471468 }
472469
473470 #[ pymethod]
@@ -476,11 +473,8 @@ impl PyByteArray {
476473 options : ByteInnerSplitOptions ,
477474 vm : & VirtualMachine ,
478475 ) -> PyResult < Vec < PyObjectRef > > {
479- self . inner ( ) . rsplit (
480- options,
481- |s, vm| Self :: new_ref ( s. to_vec ( ) , & vm. ctx ) . into ( ) ,
482- vm,
483- )
476+ self . inner ( )
477+ . rsplit ( options, |s, vm| vm. ctx . new_bytearray ( s. to_vec ( ) ) . into ( ) , vm)
484478 }
485479
486480 #[ pymethod]
@@ -490,9 +484,10 @@ impl PyByteArray {
490484 let value = self . inner ( ) ;
491485 let ( front, has_mid, back) = value. partition ( & sep, vm) ?;
492486 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 ) ,
487+ vm. ctx . new_bytearray ( front. to_vec ( ) ) ,
488+ vm. ctx
489+ . new_bytearray ( if has_mid { sep. elements } else { Vec :: new ( ) } ) ,
490+ vm. ctx . new_bytearray ( back. to_vec ( ) ) ,
496491 ) ) )
497492 }
498493
@@ -501,9 +496,10 @@ impl PyByteArray {
501496 let value = self . inner ( ) ;
502497 let ( back, has_mid, front) = value. rpartition ( & sep, vm) ?;
503498 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 ) ,
499+ vm. ctx . new_bytearray ( front. to_vec ( ) ) ,
500+ vm. ctx
501+ . new_bytearray ( if has_mid { sep. elements } else { Vec :: new ( ) } ) ,
502+ vm. ctx . new_bytearray ( back. to_vec ( ) ) ,
507503 ) ) )
508504 }
509505
@@ -515,7 +511,7 @@ impl PyByteArray {
515511 #[ pymethod]
516512 fn splitlines ( & self , options : anystr:: SplitLinesArgs , vm : & VirtualMachine ) -> Vec < PyObjectRef > {
517513 self . inner ( )
518- . splitlines ( options, |x| Self :: new_ref ( x. to_vec ( ) , & vm . ctx ) . into ( ) )
514+ . splitlines ( options, |x| vm . ctx . new_bytearray ( x. to_vec ( ) ) . into ( ) )
519515 }
520516
521517 #[ pymethod]
@@ -878,10 +874,6 @@ impl Representable for PyByteArray {
878874 }
879875}
880876
881- // fn set_value(obj: &PyObject, value: Vec<u8>) {
882- // obj.borrow_mut().kind = PyObjectPayload::Bytes { value };
883- // }
884-
885877#[ pyclass( module = false , name = "bytearray_iterator" ) ]
886878#[ derive( Debug ) ]
887879pub struct PyByteArrayIterator {
0 commit comments