161161import com .oracle .graal .python .util .OverflowException ;
162162import com .oracle .graal .python .util .PythonUtils ;
163163import com .oracle .graal .python .util .Supplier ;
164+ import com .oracle .truffle .api .CompilerAsserts ;
164165import com .oracle .truffle .api .CompilerDirectives ;
165166import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
166167import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
@@ -1980,6 +1981,17 @@ private LenNode getLenNode() {
19801981 return lenNode ;
19811982 }
19821983
1984+ private static final boolean shortCutFalse (int llen , int rlen , BinCmpOp op ) {
1985+ // shortcut: if the lengths differ, the lists differ.
1986+ CompilerAsserts .compilationConstant (op );
1987+ if (op == Eq .INSTANCE ) {
1988+ if (llen != rlen ) {
1989+ return true ;
1990+ }
1991+ }
1992+ return false ;
1993+ }
1994+
19831995 @ SuppressWarnings ("unused" )
19841996 @ Specialization (guards = {"isEmpty(left)" , "isEmpty(right)" })
19851997 boolean doEmpty (SequenceStorage left , SequenceStorage right ) {
@@ -1990,6 +2002,9 @@ boolean doEmpty(SequenceStorage left, SequenceStorage right) {
19902002 boolean doBoolStorage (BoolSequenceStorage left , BoolSequenceStorage right ) {
19912003 int llen = left .length ();
19922004 int rlen = right .length ();
2005+ if (shortCutFalse (llen , rlen , cmpOp )) {
2006+ return false ;
2007+ }
19932008 for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
19942009 int litem = PInt .intValue (left .getBoolItemNormalized (i ));
19952010 int ritem = PInt .intValue (right .getBoolItemNormalized (i ));
@@ -2004,6 +2019,9 @@ boolean doBoolStorage(BoolSequenceStorage left, BoolSequenceStorage right) {
20042019 boolean doByteStorage (ByteSequenceStorage left , ByteSequenceStorage right ) {
20052020 int llen = left .length ();
20062021 int rlen = right .length ();
2022+ if (shortCutFalse (llen , rlen , cmpOp )) {
2023+ return false ;
2024+ }
20072025 for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
20082026 byte litem = left .getByteItemNormalized (i );
20092027 byte ritem = right .getByteItemNormalized (i );
@@ -2018,6 +2036,9 @@ boolean doByteStorage(ByteSequenceStorage left, ByteSequenceStorage right) {
20182036 boolean doIntStorage (IntSequenceStorage left , IntSequenceStorage right ) {
20192037 int llen = left .length ();
20202038 int rlen = right .length ();
2039+ if (shortCutFalse (llen , rlen , cmpOp )) {
2040+ return false ;
2041+ }
20212042 for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
20222043 int litem = left .getIntItemNormalized (i );
20232044 int ritem = right .getIntItemNormalized (i );
@@ -2032,6 +2053,9 @@ boolean doIntStorage(IntSequenceStorage left, IntSequenceStorage right) {
20322053 boolean doLongStorage (LongSequenceStorage left , LongSequenceStorage right ) {
20332054 int llen = left .length ();
20342055 int rlen = right .length ();
2056+ if (shortCutFalse (llen , rlen , cmpOp )) {
2057+ return false ;
2058+ }
20352059 for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
20362060 long litem = left .getLongItemNormalized (i );
20372061 long ritem = right .getLongItemNormalized (i );
@@ -2046,6 +2070,9 @@ boolean doLongStorage(LongSequenceStorage left, LongSequenceStorage right) {
20462070 boolean doDoubleStorage (DoubleSequenceStorage left , DoubleSequenceStorage right ) {
20472071 int llen = left .length ();
20482072 int rlen = right .length ();
2073+ if (shortCutFalse (llen , rlen , cmpOp )) {
2074+ return false ;
2075+ }
20492076 for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
20502077 double litem = left .getDoubleItemNormalized (i );
20512078 double ritem = right .getDoubleItemNormalized (i );
@@ -2062,6 +2089,9 @@ boolean doGeneric(VirtualFrame frame, SequenceStorage left, SequenceStorage righ
20622089 @ CachedLibrary (limit = "getCallSiteInlineCacheMaxDepth()" ) PythonObjectLibrary lib ) {
20632090 int llen = getLenNode ().execute (left );
20642091 int rlen = getLenNode ().execute (right );
2092+ if (shortCutFalse (llen , rlen , cmpOp )) {
2093+ return false ;
2094+ }
20652095 ThreadState state ;
20662096 if (hasFrame .profile (frame != null )) {
20672097 state = PArguments .getThreadState (frame );
0 commit comments