Improves incremental compilation speed.

CompilationStateBuilder verifies contentId has not changed for
resources whose modification date has not changed, to warn the user.
This is very costly for incremental compile as most files are
not changed but we still need to read the content to verify that.
This was one of the obvious issues that showed up when I profiled
the compiler.
This patch puts contentId verification behind assert so that most
users can avoid the cost unless they hit an issue.

This patch also replaces costly isPackage check with a simpler
cache check while resolving types.

The patches cut hello world compilation time in my Mac by 30%
for incremental updates (~1.45s to ~0.95s).

Change-Id: I299768dbc7e881f2459d7bb84d33a0f5cc3f5799
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java b/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
index 92bd1fe..d64f1ff 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
@@ -510,12 +510,9 @@
 
       CompilationUnit cachedUnit = unitCache.find(resource.getPathPrefix() + resource.getPath());
 
-      ContentId resourceContentId = getResourceContentId(resource);
-      if (cachedUnit != null && cachedUnit.getLastModified() == resource.getLastModified()
-          && !cachedUnit.getContentId().equals(resourceContentId)) {
-        logger.log(TreeLogger.WARN,
-            "Modification date hasn't changed but contentId has changed for "
-            + resource.getLocation());
+      if (cachedUnit != null && cachedUnit.getLastModified() == resource.getLastModified()) {
+        // As verification is costly, this only runs the check when assertions are enabled.
+        assert verifyContentId(logger, resource, cachedUnit);
       }
 
       // Try to rescue cached units from previous sessions where a jar has been
@@ -563,6 +560,14 @@
     return compilationState;
   }
 
+  private boolean verifyContentId(TreeLogger logger, Resource resource, CompilationUnit cachedUnit) {
+    if (!cachedUnit.getContentId().equals(getResourceContentId(resource))) {
+      logger.log(TreeLogger.WARN, "Modification date hasn't changed but contentId has changed for "
+          + resource.getLocation());
+    }
+    return true;
+  }
+
   private ContentId getResourceContentId(Resource resource) {
     ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
     try {
diff --git a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
index 611f09b..ce6e733 100644
--- a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
@@ -438,7 +438,8 @@
       char[] internalNameChars = CharOperation.concatWith(compoundTypeName, '/');
       String internalName = String.valueOf(internalNameChars);
 
-      if (isPackage(internalName)) {
+      // If we already know this is a package, take the shortcut.
+      if (JreIndex.contains(internalName) || packages.contains(internalName)) {
         return null;
       }
 
diff --git a/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java
index b07c741..8e038e8 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsReportGenerationVisitor.java
@@ -32,7 +32,6 @@
 import com.google.gwt.thirdparty.guava.common.annotations.VisibleForTesting;
 import com.google.gwt.thirdparty.guava.common.collect.Lists;
 
-import java.util.LinkedList;
 import java.util.List;
 
 /**
@@ -41,7 +40,7 @@
  */
 public class JsReportGenerationVisitor extends
     JsSourceGenerationVisitorWithSizeBreakdown {
-  private final LinkedList<Range> ranges = Lists.newLinkedList();
+  private final List<Range> ranges = Lists.newArrayList();
   private final TextOutput out;
   private final boolean needSourcemapNames;
 
@@ -164,9 +163,9 @@
       // Expand overlapping range.
       Range expandedRange =
           previousRange.withNewEnd(out.getPosition(), out.getLine(), out.getColumn());
-      Range removedRange = ranges.removeLast();
+      int lastIndex = ranges.size() - 1;
+      Range removedRange = ranges.set(lastIndex, expandedRange);
       assert removedRange == previousRange;
-      ranges.add(expandedRange);
       previousRange = expandedRange;
     }
   }