@@ -556,24 +556,30 @@ impl PyList {
556
556
}
557
557
}
558
558
559
+ #[ inline]
560
+ fn cmp < F > ( & self , other : PyObjectRef , op : F , vm : & VirtualMachine ) -> PyResult < PyComparisonValue >
561
+ where
562
+ F : Fn ( & Vec < PyObjectRef > , & Vec < PyObjectRef > ) -> PyResult < bool > ,
563
+ {
564
+ let r = if let Some ( other) = other. payload_if_subclass :: < PyList > ( vm) {
565
+ Implemented ( op ( & * self . borrow_elements ( ) , & * other. borrow_elements ( ) ) ?)
566
+ } else {
567
+ NotImplemented
568
+ } ;
569
+ Ok ( r)
570
+ }
571
+
559
572
#[ pymethod( name = "__eq__" ) ]
560
573
fn eq (
561
574
zelf : PyRef < Self > ,
562
575
other : PyObjectRef ,
563
576
vm : & VirtualMachine ,
564
577
) -> PyResult < PyComparisonValue > {
565
- let value = if zelf. as_object ( ) . is ( & other) {
566
- Implemented ( true )
567
- } else if let Some ( other) = other. payload_if_subclass :: < PyList > ( vm) {
568
- Implemented ( sequence:: eq (
569
- vm,
570
- & zelf. borrow_sequence ( ) ,
571
- & other. borrow_sequence ( ) ,
572
- ) ?)
578
+ if zelf. as_object ( ) . is ( & other) {
579
+ Ok ( Implemented ( true ) )
573
580
} else {
574
- NotImplemented
575
- } ;
576
- Ok ( value)
581
+ zelf. cmp ( other, |a, b| sequence:: eq ( vm, a, b) , vm)
582
+ }
577
583
}
578
584
579
585
#[ pymethod( name = "__ne__" ) ]
@@ -586,43 +592,23 @@ impl PyList {
586
592
}
587
593
588
594
#[ pymethod( name = "__lt__" ) ]
589
- fn lt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
590
- if let Some ( other) = other. payload_if_subclass :: < PyList > ( vm) {
591
- let res = sequence:: lt ( vm, & self . borrow_sequence ( ) , & other. borrow_sequence ( ) ) ?;
592
- Ok ( vm. new_bool ( res) )
593
- } else {
594
- Ok ( vm. ctx . not_implemented ( ) )
595
- }
595
+ fn lt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
596
+ self . cmp ( other, |a, b| sequence:: lt ( vm, a, b) , vm)
596
597
}
597
598
598
599
#[ pymethod( name = "__gt__" ) ]
599
- fn gt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
600
- if let Some ( other) = other. payload_if_subclass :: < PyList > ( vm) {
601
- let res = sequence:: gt ( vm, & self . borrow_sequence ( ) , & other. borrow_sequence ( ) ) ?;
602
- Ok ( vm. new_bool ( res) )
603
- } else {
604
- Ok ( vm. ctx . not_implemented ( ) )
605
- }
600
+ fn gt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
601
+ self . cmp ( other, |a, b| sequence:: gt ( vm, a, b) , vm)
606
602
}
607
603
608
604
#[ pymethod( name = "__ge__" ) ]
609
- fn ge ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
610
- if let Some ( other) = other. payload_if_subclass :: < PyList > ( vm) {
611
- let res = sequence:: ge ( vm, & self . borrow_sequence ( ) , & other. borrow_sequence ( ) ) ?;
612
- Ok ( vm. new_bool ( res) )
613
- } else {
614
- Ok ( vm. ctx . not_implemented ( ) )
615
- }
605
+ fn ge ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
606
+ self . cmp ( other, |a, b| sequence:: ge ( vm, a, b) , vm)
616
607
}
617
608
618
609
#[ pymethod( name = "__le__" ) ]
619
- fn le ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
620
- if let Some ( other) = other. payload_if_subclass :: < PyList > ( vm) {
621
- let res = sequence:: le ( vm, & self . borrow_sequence ( ) , & other. borrow_sequence ( ) ) ?;
622
- Ok ( vm. new_bool ( res) )
623
- } else {
624
- Ok ( vm. ctx . not_implemented ( ) )
625
- }
610
+ fn le ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
611
+ self . cmp ( other, |a, b| sequence:: le ( vm, a, b) , vm)
626
612
}
627
613
628
614
#[ pymethod( name = "__delitem__" ) ]
0 commit comments