@@ -1549,114 +1549,75 @@ PNotImplemented contains(@SuppressWarnings("unused") Object self, @SuppressWarni
1549
1549
1550
1550
@ Builtin (name = __LT__ , fixedNumOfArguments = 2 )
1551
1551
@ GenerateNodeFactory
1552
- abstract static class LtNode extends PythonBinaryBuiltinNode {
1552
+ abstract static class LtNode extends ListComparisonNode {
1553
1553
1554
1554
@ Specialization
1555
1555
boolean contains (PList self , PList other ,
1556
1556
@ Cached ("create(__EQ__, __EQ__, __EQ__)" ) BinaryComparisonNode eqNode ,
1557
1557
@ Cached ("create(__LT__, __GT__, __LT__)" ) BinaryComparisonNode ltNode ) {
1558
- int len = self .len ();
1559
- int len2 = other .len ();
1560
- int min = Math .min (len , len2 );
1561
- for (int i = 0 ; i < min ; i ++) {
1562
- Object left = self .getItem (i );
1563
- Object right = other .getItem (i );
1564
- if (!eqNode .executeBool (left , right )) {
1565
- return ltNode .executeBool (left , right );
1566
- }
1567
- }
1568
- return len < len2 ;
1569
- }
1570
-
1571
- @ Fallback
1572
- PNotImplemented contains (@ SuppressWarnings ("unused" ) Object self , @ SuppressWarnings ("unused" ) Object other ) {
1573
- return PNotImplemented .NOT_IMPLEMENTED ;
1558
+ return doComparison (self , other , eqNode , ltNode );
1574
1559
}
1575
1560
}
1576
1561
1577
1562
@ Builtin (name = __GT__ , fixedNumOfArguments = 2 )
1578
1563
@ GenerateNodeFactory
1579
- abstract static class GtNode extends PythonBinaryBuiltinNode {
1564
+ abstract static class GtNode extends ListComparisonNode {
1580
1565
1581
1566
@ Specialization
1582
1567
boolean contains (PList self , PList other ,
1583
1568
@ Cached ("create(__EQ__, __EQ__, __EQ__)" ) BinaryComparisonNode eqNode ,
1584
1569
@ Cached ("create(__GT__, __LT__, __GT__)" ) BinaryComparisonNode gtNode ) {
1585
- int len = self .len ();
1586
- int len2 = other .len ();
1587
- int min = Math .min (len , len2 );
1588
- for (int i = 0 ; i < min ; i ++) {
1589
- Object left = self .getItem (i );
1590
- Object right = other .getItem (i );
1591
- if (!eqNode .executeBool (left , right )) {
1592
- return gtNode .executeBool (left , right );
1593
- }
1594
- }
1595
- return len > len2 ;
1596
- }
1597
-
1598
- @ Fallback
1599
- PNotImplemented contains (@ SuppressWarnings ("unused" ) Object self , @ SuppressWarnings ("unused" ) Object other ) {
1600
- return PNotImplemented .NOT_IMPLEMENTED ;
1570
+ return doComparison (self , other , eqNode , gtNode );
1601
1571
}
1602
1572
}
1603
1573
1604
1574
@ Builtin (name = __GE__ , fixedNumOfArguments = 2 )
1605
1575
@ GenerateNodeFactory
1606
- abstract static class GeNode extends PythonBinaryBuiltinNode {
1576
+ abstract static class GeNode extends ListComparisonNode {
1607
1577
1608
1578
@ Specialization
1609
1579
boolean doPTuple (PList left , PList right ,
1610
1580
@ Cached ("create(__EQ__, __EQ__, __EQ__)" ) BinaryComparisonNode eqNode ,
1611
1581
@ Cached ("create(__GE__, __LE__, __GE__)" ) BinaryComparisonNode geNode ) {
1612
- int llen = left .len ();
1613
- int rlen = right .len ();
1614
- int min = Math .min (llen , rlen );
1615
- for (int i = 0 ; i < min ; i ++) {
1616
- Object oleft = left .getItem (i );
1617
- Object oright = right .getItem (i );
1618
- if (!eqNode .executeBool (oleft , oright )) {
1619
- return geNode .executeBool (oleft , oright );
1620
- }
1621
- }
1622
- return llen >= rlen ;
1582
+ return doComparison (left , right , eqNode , geNode );
1623
1583
}
1624
-
1625
- @ Fallback
1626
- @ SuppressWarnings ("unused" )
1627
- PNotImplemented doOther (Object left , Object right ) {
1628
- return PNotImplemented .NOT_IMPLEMENTED ;
1629
- }
1630
-
1631
1584
}
1632
1585
1633
1586
@ Builtin (name = __LE__ , fixedNumOfArguments = 2 )
1634
1587
@ GenerateNodeFactory
1635
- abstract static class LeNode extends PythonBinaryBuiltinNode {
1588
+ abstract static class LeNode extends ListComparisonNode {
1636
1589
1637
1590
@ Specialization
1638
- boolean doPTuple (PList left , PList right ,
1591
+ boolean doPList (PList left , PList right ,
1639
1592
@ Cached ("create(__EQ__, __EQ__, __EQ__)" ) BinaryComparisonNode eqNode ,
1640
- @ Cached ("create(__LE__, __GE__, __LE__)" ) BinaryComparisonNode geNode ) {
1641
- int llen = left .len ();
1642
- int rlen = right .len ();
1643
- int min = Math .min (llen , rlen );
1593
+ @ Cached ("create(__LE__, __GE__, __LE__)" ) BinaryComparisonNode leNode ) {
1594
+ return doComparison (left , right , eqNode , leNode );
1595
+ }
1596
+ }
1597
+
1598
+ abstract static class ListComparisonNode extends PythonBinaryBuiltinNode {
1599
+
1600
+ static boolean doComparison (PList self , PList other ,
1601
+ BinaryComparisonNode eqNode ,
1602
+ BinaryComparisonNode compNode ) {
1603
+ int len = self .len ();
1604
+ int len2 = other .len ();
1605
+ int min = Math .min (len , len2 );
1644
1606
for (int i = 0 ; i < min ; i ++) {
1645
- Object oleft = left .getItem (i );
1646
- Object oright = right .getItem (i );
1647
- if (!eqNode .executeBool (oleft , oright )) {
1648
- return geNode .executeBool (oleft , oright );
1607
+ Object left = self .getItem (i );
1608
+ Object right = other .getItem (i );
1609
+ if (!eqNode .executeBool (left , right )) {
1610
+ return compNode .executeBool (left , right );
1649
1611
}
1650
1612
}
1651
- return llen <= rlen ;
1613
+ return compNode . executeBool ( len , len2 ) ;
1652
1614
}
1653
1615
1654
1616
@ Fallback
1655
1617
@ SuppressWarnings ("unused" )
1656
1618
PNotImplemented doOther (Object left , Object right ) {
1657
1619
return PNotImplemented .NOT_IMPLEMENTED ;
1658
1620
}
1659
-
1660
1621
}
1661
1622
1662
1623
@ Builtin (name = __CONTAINS__ , fixedNumOfArguments = 2 )
0 commit comments