Reviewers: scottb,

Description:
Calculates result of getSourceName() one time, so reuse because of CU
cache.
Prepares SAXParserFActory one time, so avoids expensive ClassLoader
lookups.


Please review this at http://gwt-code-reviews.appspot.com/1438801/

Affected files:
  M dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
  M dev/core/src/com/google/gwt/dev/util/xml/ReflectiveParser.java
  M dev/core/test/com/google/gwt/dev/javac/CompiledClassTest.java


Index: dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
===================================================================
--- dev/core/src/com/google/gwt/dev/javac/CompiledClass.java (revision 10077)
+++ dev/core/src/com/google/gwt/dev/javac/CompiledClass.java    (working copy)
@@ -38,6 +38,7 @@

   private final CompiledClass enclosingClass;
   private final String internalName;
+  private final String sourceName;
   private final boolean isLocal;
   private transient TypeData typeData;
   private CompilationUnit unit;
@@ -65,6 +66,7 @@
       String internalName) {
     this.enclosingClass = enclosingClass;
     this.internalName = StringInterner.get().intern(internalName);
+ this.sourceName = StringInterner.get().intern(InternalName.toSourceName(internalName));
     this.cacheToken = diskCache.writeByteArray(classBytes);
     this.isLocal = isLocal;
   }
@@ -109,7 +111,7 @@
    * Returns the qualified source name, e.g. {@code java.util.Map.Entry}.
    */
   public String getSourceName() {
- return StringInterner.get().intern(InternalName.toSourceName(internalName));
+    return sourceName;
   }

   public TypeData getTypeData() {
Index: dev/core/src/com/google/gwt/dev/util/xml/ReflectiveParser.java
===================================================================
--- dev/core/src/com/google/gwt/dev/util/xml/ReflectiveParser.java (revision 10077) +++ dev/core/src/com/google/gwt/dev/util/xml/ReflectiveParser.java (working copy)
@@ -44,6 +44,26 @@
  * elements) is ignored, so think attributes.
  */
 public final class ReflectiveParser {
+
+  private static SAXParserFactory saxParserFactory;
+
+ private static SAXParserFactory getSAXParserFactory() throws ParserConfigurationException,
+      SAXException {
+    if (saxParserFactory == null) {
+      Thread currentThread = Thread.currentThread();
+      ClassLoader oldClassLoader = currentThread.getContextClassLoader();
+      try {
+        // use system ClassLoader to avoid using expensive GWT ClassLoader
+ currentThread.setContextClassLoader(ClassLoader.getSystemClassLoader());
+        saxParserFactory = SAXParserFactory.newInstance();
+        saxParserFactory.setFeature(
+ "http://apache.org/xml/features/nonvalidating/load-external-dtd";, false);
+      } finally {
+        currentThread.setContextClassLoader(oldClassLoader);
+      }
+    }
+    return saxParserFactory;
+  }

   private static final class Impl extends DefaultHandler {

@@ -320,10 +340,7 @@
       Throwable caught = null;
       try {
         this.reader = reader;
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-        factory.setFeature(
-            "http://apache.org/xml/features/nonvalidating/load-external-dtd";,
-            false);
+        SAXParserFactory factory = getSAXParserFactory();
         SAXParser parser = factory.newSAXParser();
         InputSource inputSource = new InputSource(this.reader);
         XMLReader xmlReader = parser.getXMLReader();
Index: dev/core/test/com/google/gwt/dev/javac/CompiledClassTest.java
===================================================================
--- dev/core/test/com/google/gwt/dev/javac/CompiledClassTest.java (revision 10077) +++ dev/core/test/com/google/gwt/dev/javac/CompiledClassTest.java (working copy)
@@ -26,7 +26,7 @@
   static byte[] dummyByteCode = {
     (byte) 0xDE, (byte) 0xAD, (byte)0xBE, (byte)0xEF
   };
-  static final String DUMMY_NAME = "com.example.DeadBeef";
+  static final String DUMMY_NAME = "com/example/DeadBeef";

   public void testCompiledClassSerialization() throws Exception {
CompiledClass writeObject = new CompiledClass(dummyByteCode, null, false, DUMMY_NAME);


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to