groovy type dfa: start time measurement only for long analyses
authorpeter <peter@jetbrains.com>
Wed, 27 May 2015 12:09:18 +0000 (14:09 +0200)
committerpeter <peter@jetbrains.com>
Wed, 27 May 2015 12:11:13 +0000 (14:11 +0200)
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DFAEngine.java

index 219503ee21d1a2b01ec42c169c9ef7c388d164ea..44516681c8703941841bb6dd619afe34e35db855 100644 (file)
@@ -78,15 +78,11 @@ public class DFAEngine<E> {
 
   @Nullable
   private ArrayList<E> performDFA(boolean timeout) {
-    long msLimit = Registry.intValue("ide.dfa.time.limit.online");
-    WorkingTimeMeasurer measurer = new WorkingTimeMeasurer(msLimit * 1000 * 1000);
+    WorkingTimeMeasurer measurer = null;
 
-    ArrayList<E> info = new ArrayList<E>(myFlow.length);
+    ArrayList<E> info = new ArrayList<E>(Collections.nCopies(myFlow.length, myDfa.initial()));
     CallEnvironment env = new MyCallEnvironment(myFlow.length);
-    for (int i = 0; i < myFlow.length; i++) {
-      info.add(myDfa.initial());
-    }
-
+    
     boolean[] visited = new boolean[myFlow.length];
 
     final boolean forward = myDfa.isForward();
@@ -103,7 +99,16 @@ public class DFAEngine<E> {
 
         while (!workList.isEmpty()) {
           count++;
-          if (timeout && count % 512 == 0 && measurer.isTimeOver()) return null;
+          if (timeout && count % 512 == 0) {
+            if (measurer == null) {
+              long msLimit = Registry.intValue("ide.dfa.time.limit.online");
+
+              measurer = new WorkingTimeMeasurer(msLimit * 1000 * 1000);
+            }
+            else if (measurer.isTimeOver()) {
+              return null;
+            }
+          }
 
           ProgressManager.checkCanceled();
           final Instruction curr = workList.remove();