@@ -61,18 +61,18 @@ impl Deref for PyBytes {
6161 type Target = [ u8 ] ;
6262
6363 fn deref ( & self ) -> & [ u8 ] {
64- & self . inner . elements
64+ self . as_bytes ( )
6565 }
6666}
6767
6868impl AsRef < [ u8 ] > for PyBytes {
6969 fn as_ref ( & self ) -> & [ u8 ] {
70- & self . inner . elements
70+ self . as_bytes ( )
7171 }
7272}
7373impl AsRef < [ u8 ] > for PyBytesRef {
7474 fn as_ref ( & self ) -> & [ u8 ] {
75- & self . inner . elements
75+ self . as_bytes ( )
7676 }
7777}
7878
@@ -133,7 +133,7 @@ impl PyBytes {
133133
134134 #[ inline]
135135 pub fn as_bytes ( & self ) -> & [ u8 ] {
136- & self . inner . elements
136+ self . inner . as_bytes ( )
137137 }
138138
139139 #[ pymethod( magic) ]
@@ -147,7 +147,7 @@ impl PyBytes {
147147
148148 #[ pymethod( magic) ]
149149 fn sizeof ( & self ) -> usize {
150- size_of :: < Self > ( ) + self . inner . elements . len ( ) * size_of :: < u8 > ( )
150+ size_of :: < Self > ( ) + self . len ( ) * size_of :: < u8 > ( )
151151 }
152152
153153 #[ pymethod( magic) ]
@@ -172,13 +172,9 @@ impl PyBytes {
172172 fn _getitem ( & self , needle : & PyObject , vm : & VirtualMachine ) -> PyResult {
173173 match SequenceIndex :: try_from_borrowed_object ( vm, needle, "byte" ) ? {
174174 SequenceIndex :: Int ( i) => self
175- . inner
176- . elements
177175 . getitem_by_index ( vm, i)
178176 . map ( |x| vm. ctx . new_int ( x) . into ( ) ) ,
179177 SequenceIndex :: Slice ( slice) => self
180- . inner
181- . elements
182178 . getitem_by_slice ( vm, slice)
183179 . map ( |x| vm. ctx . new_bytes ( x) . into ( ) ) ,
184180 }
@@ -294,15 +290,15 @@ impl PyBytes {
294290 #[ pymethod]
295291 fn endswith ( & self , options : anystr:: StartsEndsWithArgs , vm : & VirtualMachine ) -> PyResult < bool > {
296292 let ( affix, substr) =
297- match options. prepare ( & self . inner . elements [ .. ] , self . len ( ) , |s, r| s. get_bytes ( r) ) {
293+ match options. prepare ( self . as_bytes ( ) , self . len ( ) , |s, r| s. get_bytes ( r) ) {
298294 Some ( x) => x,
299295 None => return Ok ( false ) ,
300296 } ;
301297 substr. py_startsendswith (
302298 affix,
303299 "endswith" ,
304300 "bytes" ,
305- |s, x : & PyBytesInner | s. ends_with ( & x . elements [ .. ] ) ,
301+ |s, x : & PyBytesInner | s. ends_with ( x . as_bytes ( ) ) ,
306302 vm,
307303 )
308304 }
@@ -314,15 +310,15 @@ impl PyBytes {
314310 vm : & VirtualMachine ,
315311 ) -> PyResult < bool > {
316312 let ( affix, substr) =
317- match options. prepare ( & self . inner . elements [ .. ] , self . len ( ) , |s, r| s. get_bytes ( r) ) {
313+ match options. prepare ( self . as_bytes ( ) , self . len ( ) , |s, r| s. get_bytes ( r) ) {
318314 Some ( x) => x,
319315 None => return Ok ( false ) ,
320316 } ;
321317 substr. py_startsendswith (
322318 affix,
323319 "startswith" ,
324320 "bytes" ,
325- |s, x : & PyBytesInner | s. starts_with ( & x . elements [ .. ] ) ,
321+ |s, x : & PyBytesInner | s. starts_with ( x . as_bytes ( ) ) ,
326322 vm,
327323 )
328324 }
@@ -539,12 +535,7 @@ impl PyBytes {
539535
540536 #[ pymethod( magic) ]
541537 fn getnewargs ( & self , vm : & VirtualMachine ) -> PyTupleRef {
542- let param: Vec < PyObjectRef > = self
543- . inner
544- . elements
545- . iter ( )
546- . map ( |x| x. to_pyobject ( vm) )
547- . collect ( ) ;
538+ let param: Vec < PyObjectRef > = self . elements ( ) . map ( |x| x. to_pyobject ( vm) ) . collect ( ) ;
548539 PyTuple :: new_ref ( param, & vm. ctx )
549540 }
550541
@@ -562,7 +553,7 @@ impl PyBytes {
562553 zelf : PyRef < Self > ,
563554 vm : & VirtualMachine ,
564555 ) -> ( PyTypeRef , PyTupleRef , Option < PyDictRef > ) {
565- let bytes = PyBytes :: from ( zelf. inner . elements . clone ( ) ) . to_pyobject ( vm) ;
556+ let bytes = PyBytes :: from ( zelf. to_vec ( ) ) . to_pyobject ( vm) ;
566557 (
567558 zelf. class ( ) . to_owned ( ) ,
568559 PyTuple :: new_ref ( vec ! [ bytes] , & vm. ctx ) ,
@@ -620,8 +611,7 @@ impl AsSequence for PyBytes {
620611 } ) ,
621612 item : atomic_func ! ( |seq, i, vm| {
622613 PyBytes :: sequence_downcast( seq)
623- . inner
624- . elements
614+ . as_bytes( )
625615 . getitem_by_index( vm, i)
626616 . map( |x| vm. ctx. new_bytes( vec![ x] ) . into( ) )
627617 } ) ,
0 commit comments