161
161
import com .oracle .graal .python .util .OverflowException ;
162
162
import com .oracle .graal .python .util .PythonUtils ;
163
163
import com .oracle .graal .python .util .Supplier ;
164
+ import com .oracle .truffle .api .CompilerAsserts ;
164
165
import com .oracle .truffle .api .CompilerDirectives ;
165
166
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
166
167
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
@@ -1980,6 +1981,17 @@ private LenNode getLenNode() {
1980
1981
return lenNode ;
1981
1982
}
1982
1983
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
+
1983
1995
@ SuppressWarnings ("unused" )
1984
1996
@ Specialization (guards = {"isEmpty(left)" , "isEmpty(right)" })
1985
1997
boolean doEmpty (SequenceStorage left , SequenceStorage right ) {
@@ -1990,6 +2002,9 @@ boolean doEmpty(SequenceStorage left, SequenceStorage right) {
1990
2002
boolean doBoolStorage (BoolSequenceStorage left , BoolSequenceStorage right ) {
1991
2003
int llen = left .length ();
1992
2004
int rlen = right .length ();
2005
+ if (shortCutFalse (llen , rlen , cmpOp )) {
2006
+ return false ;
2007
+ }
1993
2008
for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
1994
2009
int litem = PInt .intValue (left .getBoolItemNormalized (i ));
1995
2010
int ritem = PInt .intValue (right .getBoolItemNormalized (i ));
@@ -2004,6 +2019,9 @@ boolean doBoolStorage(BoolSequenceStorage left, BoolSequenceStorage right) {
2004
2019
boolean doByteStorage (ByteSequenceStorage left , ByteSequenceStorage right ) {
2005
2020
int llen = left .length ();
2006
2021
int rlen = right .length ();
2022
+ if (shortCutFalse (llen , rlen , cmpOp )) {
2023
+ return false ;
2024
+ }
2007
2025
for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
2008
2026
byte litem = left .getByteItemNormalized (i );
2009
2027
byte ritem = right .getByteItemNormalized (i );
@@ -2018,6 +2036,9 @@ boolean doByteStorage(ByteSequenceStorage left, ByteSequenceStorage right) {
2018
2036
boolean doIntStorage (IntSequenceStorage left , IntSequenceStorage right ) {
2019
2037
int llen = left .length ();
2020
2038
int rlen = right .length ();
2039
+ if (shortCutFalse (llen , rlen , cmpOp )) {
2040
+ return false ;
2041
+ }
2021
2042
for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
2022
2043
int litem = left .getIntItemNormalized (i );
2023
2044
int ritem = right .getIntItemNormalized (i );
@@ -2032,6 +2053,9 @@ boolean doIntStorage(IntSequenceStorage left, IntSequenceStorage right) {
2032
2053
boolean doLongStorage (LongSequenceStorage left , LongSequenceStorage right ) {
2033
2054
int llen = left .length ();
2034
2055
int rlen = right .length ();
2056
+ if (shortCutFalse (llen , rlen , cmpOp )) {
2057
+ return false ;
2058
+ }
2035
2059
for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
2036
2060
long litem = left .getLongItemNormalized (i );
2037
2061
long ritem = right .getLongItemNormalized (i );
@@ -2046,6 +2070,9 @@ boolean doLongStorage(LongSequenceStorage left, LongSequenceStorage right) {
2046
2070
boolean doDoubleStorage (DoubleSequenceStorage left , DoubleSequenceStorage right ) {
2047
2071
int llen = left .length ();
2048
2072
int rlen = right .length ();
2073
+ if (shortCutFalse (llen , rlen , cmpOp )) {
2074
+ return false ;
2075
+ }
2049
2076
for (int i = 0 ; i < Math .min (llen , rlen ); i ++) {
2050
2077
double litem = left .getDoubleItemNormalized (i );
2051
2078
double ritem = right .getDoubleItemNormalized (i );
@@ -2062,6 +2089,9 @@ boolean doGeneric(VirtualFrame frame, SequenceStorage left, SequenceStorage righ
2062
2089
@ CachedLibrary (limit = "getCallSiteInlineCacheMaxDepth()" ) PythonObjectLibrary lib ) {
2063
2090
int llen = getLenNode ().execute (left );
2064
2091
int rlen = getLenNode ().execute (right );
2092
+ if (shortCutFalse (llen , rlen , cmpOp )) {
2093
+ return false ;
2094
+ }
2065
2095
ThreadState state ;
2066
2096
if (hasFrame .profile (frame != null )) {
2067
2097
state = PArguments .getThreadState (frame );
0 commit comments