LongRangeSet.RangeSet#plus: convert to simple range if number of sets exceeds 3

Fixes IDEA-193987 IDE freeze when turn on code inspection data flow for Java
This commit is contained in:
Tagir Valeev
2018-06-18 17:18:20 +07:00
parent d495f88c6a
commit f2f23f3610
3 changed files with 31 additions and 0 deletions
@@ -1256,6 +1256,9 @@ public abstract class LongRangeSet {
@NotNull
@Override
public LongRangeSet plus(LongRangeSet other, boolean isLong) {
if (myRanges.length > 6) {
return range(min(), max()).plus(other, isLong);
}
LongRangeSet result = empty();
for (int i = 0; i < myRanges.length; i += 2) {
result = result.union(range(myRanges[i], myRanges[i + 1]).plus(other, isLong));
@@ -0,0 +1,26 @@
import java.util.*;
class Test {
native boolean get();
void test() {
int x = get() ? 0 : 1<<30;
x = x + (get() ? 0 : 1<<29);
x = x + (get() ? 0 : 1<<28);
x = x + (get() ? 0 : 1<<27);
x = x + (get() ? 0 : 1<<26);
x = x + (get() ? 0 : 1<<25);
x = x + (get() ? 0 : 1<<24);
x = x + (get() ? 0 : 1<<23);
x = x + (get() ? 0 : 1<<22);
x = x + (get() ? 0 : 1<<21);
x = x + (get() ? 0 : 1<<20);
x = x + (get() ? 0 : 1<<19);
x = x + (get() ? 0 : 1<<18);
x = x + (get() ? 0 : 1<<17);
if (<warning descr="Condition 'x < 0' is always 'false'">x < 0</warning>) {
System.out.println("Impossible");
}
}
}
@@ -62,4 +62,6 @@ public class DataFlowRangeAnalysisTest extends DataFlowInspectionTestCase {
public void testLongRangePlusMinus() { doTest(); }
public void testFebruary31() { doTest(); }
public void testManyAdditionsDoNotCauseExponentialBlowUp() { doTest(); }
}