@@ -295,7 +295,7 @@ impl<'a, R> core::iter::IntoIterator for &'a PyTuple<R> {
295295 type IntoIter = core:: slice:: Iter < ' a , R > ;
296296
297297 fn into_iter ( self ) -> Self :: IntoIter {
298- self . iter ( )
298+ self . as_slice ( ) . iter ( )
299299 }
300300}
301301
@@ -304,7 +304,7 @@ impl<'a, R> core::iter::IntoIterator for &'a Py<PyTuple<R>> {
304304 type IntoIter = core:: slice:: Iter < ' a , R > ;
305305
306306 fn into_iter ( self ) -> Self :: IntoIter {
307- self . iter ( )
307+ PyTuple :: as_slice ( self ) . iter ( )
308308 }
309309}
310310
@@ -313,23 +313,6 @@ impl<R> PyTuple<R> {
313313 pub fn as_slice ( & self ) -> & [ R ] {
314314 & self . elements
315315 }
316-
317- #[ inline]
318- #[ must_use]
319- pub fn len ( & self ) -> usize {
320- self . as_slice ( ) . len ( )
321- }
322-
323- #[ inline]
324- #[ must_use]
325- pub fn is_empty ( & self ) -> bool {
326- self . as_slice ( ) . is_empty ( )
327- }
328-
329- #[ inline]
330- pub fn iter ( & self ) -> core:: slice:: Iter < ' _ , R > {
331- self . as_slice ( ) . iter ( )
332- }
333316}
334317
335318impl PyTuple < PyObjectRef > {
@@ -367,7 +350,7 @@ impl PyTuple<PyObjectRef> {
367350 }
368351
369352 fn repeat ( zelf : PyRef < Self > , value : isize , vm : & VirtualMachine ) -> PyResult < PyRef < Self > > {
370- Ok ( if zelf. is_empty ( ) || value == 0 {
353+ Ok ( if zelf. as_slice ( ) . is_empty ( ) || value == 0 {
371354 vm. ctx . empty_tuple . clone ( )
372355 } else if value == 1 && zelf. class ( ) . is ( vm. ctx . types . tuple_type ) {
373356 // Special case: when some `tuple` is multiplied by `1`,
@@ -392,21 +375,6 @@ impl Py<PyTuple> {
392375 self . payload ( ) . as_slice ( )
393376 }
394377
395- #[ inline]
396- pub fn len ( & self ) -> usize {
397- self . as_slice ( ) . len ( )
398- }
399-
400- #[ inline]
401- pub fn is_empty ( & self ) -> bool {
402- self . as_slice ( ) . is_empty ( )
403- }
404-
405- #[ inline]
406- pub fn iter ( & self ) -> core:: slice:: Iter < ' _ , PyObjectRef > {
407- self . as_slice ( ) . iter ( )
408- }
409-
410378 pub fn extract_tuple < ' a , T : FromPyTuple < ' a > > ( & ' a self , vm : & VirtualMachine ) -> PyResult < T > {
411379 T :: from_pytuple ( self , vm)
412380 }
@@ -453,12 +421,13 @@ impl PyTuple {
453421 vm : & VirtualMachine ,
454422 ) -> PyArithmeticValue < PyRef < Self > > {
455423 let added = other. downcast :: < Self > ( ) . map ( |other| {
456- if other. is_empty ( ) && zelf. class ( ) . is ( vm. ctx . types . tuple_type ) {
424+ if other. as_slice ( ) . is_empty ( ) && zelf. class ( ) . is ( vm. ctx . types . tuple_type ) {
457425 zelf
458- } else if zelf. is_empty ( ) && other. class ( ) . is ( vm. ctx . types . tuple_type ) {
426+ } else if zelf. as_slice ( ) . is_empty ( ) && other. class ( ) . is ( vm. ctx . types . tuple_type ) {
459427 other
460428 } else {
461429 let elements = zelf
430+ . as_slice ( )
462431 . iter ( )
463432 . chain ( other. as_slice ( ) )
464433 . cloned ( )
@@ -486,7 +455,7 @@ impl PyTuple {
486455 #[ inline]
487456 #[ must_use]
488457 pub fn __len__ ( & self ) -> usize {
489- self . len ( )
458+ self . as_slice ( ) . len ( )
490459 }
491460
492461 fn __mul__ ( zelf : PyRef < Self > , value : ArgSize , vm : & VirtualMachine ) -> PyResult < PyRef < Self > > {
@@ -520,8 +489,8 @@ impl PyTuple {
520489 range : OptionalRangeArgs ,
521490 vm : & VirtualMachine ,
522491 ) -> PyResult < usize > {
523- let ( start, stop) = range. saturate ( self . len ( ) , vm) ?;
524- for ( index, element) in self . iter ( ) . enumerate ( ) . take ( stop) . skip ( start) {
492+ let ( start, stop) = range. saturate ( self . as_slice ( ) . len ( ) , vm) ?;
493+ for ( index, element) in self . as_slice ( ) . iter ( ) . enumerate ( ) . take ( stop) . skip ( start) {
525494 if vm. identical_or_equal ( element, & needle) ? {
526495 return Ok ( index) ;
527496 }
@@ -568,7 +537,9 @@ impl PyTuple {
568537impl AsMapping for PyTuple {
569538 fn as_mapping ( ) -> & ' static PyMappingMethods {
570539 static AS_MAPPING : LazyLock < PyMappingMethods > = LazyLock :: new ( || PyMappingMethods {
571- length : atomic_func ! ( |mapping, _vm| Ok ( PyTuple :: mapping_downcast( mapping) . len( ) ) ) ,
540+ length : atomic_func ! ( |mapping, _vm| {
541+ Ok ( PyTuple :: mapping_downcast( mapping) . as_slice( ) . len( ) )
542+ } ) ,
572543 subscript : atomic_func ! (
573544 |mapping, needle, vm| PyTuple :: mapping_downcast( mapping) . _getitem( needle, vm)
574545 ) ,
@@ -615,7 +586,7 @@ impl AsNumber for PyTuple {
615586 static AS_NUMBER : PyNumberMethods = PyNumberMethods {
616587 boolean : Some ( |number, _vm| {
617588 let zelf = number. obj . downcast_ref :: < PyTuple > ( ) . unwrap ( ) ;
618- Ok ( !zelf. is_empty ( ) )
589+ Ok ( !zelf. as_slice ( ) . is_empty ( ) )
619590 } ) ,
620591 ..PyNumberMethods :: NOT_IMPLEMENTED
621592 } ;
@@ -641,9 +612,10 @@ impl Comparable for PyTuple {
641612 return Ok ( res. into ( ) ) ;
642613 }
643614 let other = class_or_notimplemented ! ( Self , other) ;
644- zelf. iter ( )
615+ zelf. as_slice ( )
616+ . iter ( )
645617 . map ( |o| & * * o)
646- . richcompare ( other. iter ( ) . map ( |o| & * * o) , op, vm)
618+ . richcompare ( other. as_slice ( ) . iter ( ) . map ( |o| & * * o) , op, vm)
647619 . map ( PyComparisonValue :: Implemented )
648620 }
649621}
@@ -660,13 +632,20 @@ impl Iterable for PyTuple {
660632impl Representable for PyTuple {
661633 #[ inline]
662634 fn repr ( zelf : & Py < Self > , vm : & VirtualMachine ) -> PyResult < PyStrRef > {
663- let s = if zelf. is_empty ( ) {
635+ let s = if zelf. as_slice ( ) . is_empty ( ) {
664636 vm. ctx . intern_str ( "()" ) . to_owned ( )
665637 } else if let Some ( _guard) = ReprGuard :: enter ( vm, zelf. as_object ( ) ) {
666- let s = if zelf. len ( ) == 1 {
667- wtf8_concat ! ( "(" , zelf. elements [ 0 ] . repr( vm) ?. as_wtf8( ) , ",)" )
638+ let s = if zelf. as_slice ( ) . len ( ) == 1 {
639+ wtf8_concat ! ( "(" , zelf. as_slice ( ) [ 0 ] . repr( vm) ?. as_wtf8( ) , ",)" )
668640 } else {
669- collection_repr ( None , "(" , ")" , "()" , zelf. iter ( ) . map ( |o| & * * o) , vm) ?
641+ collection_repr (
642+ None ,
643+ "(" ,
644+ ")" ,
645+ "()" ,
646+ zelf. as_slice ( ) . iter ( ) . map ( |o| & * * o) ,
647+ vm,
648+ ) ?
670649 } ;
671650 vm. ctx . new_str ( s)
672651 } else {
@@ -733,14 +712,14 @@ impl PyPayload for PyTupleIterator {
733712impl PyTupleIterator {
734713 #[ pymethod]
735714 fn __length_hint__ ( & self ) -> usize {
736- self . internal . lock ( ) . length_hint ( |obj| obj. len ( ) )
715+ self . internal . lock ( ) . length_hint ( |obj| obj. as_slice ( ) . len ( ) )
737716 }
738717
739718 #[ pymethod]
740719 fn __setstate__ ( & self , state : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
741720 self . internal
742721 . lock ( )
743- . set_state ( & state, |obj, pos| pos. min ( obj. len ( ) ) , vm)
722+ . set_state ( & state, |obj, pos| pos. min ( obj. as_slice ( ) . len ( ) ) , vm)
744723 }
745724
746725 #[ pymethod]
0 commit comments