Reviewers: bobv,

Description:
This is the first of a couple of patches that will remove certain JSNI
code paths in generated code from being traversed in DevMode.  This
should allow DevMode to run faster.


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

Affected files:
M user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java


Index: user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java diff --git a/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java b/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java index 633d2381ccfaa235b78623030c273a8d4d489ade..6a8f96329986ec982428d73c92c1510c5d6f8a3e 100644 --- a/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java +++ b/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java
@@ -72,7 +72,19 @@ import java.util.Set;
  * public ResourcePrototype[] getResources() {
  *   return new ResourcePrototype[] { resource() };
  * }
- * public native ResourcePrototype getResource(String name) /-{
+ * private static HashMap<String, ResourcePrototype> resourceMap;
+ * public ResourcePrototype getResource(String name) {
+ *   if (GWT.isScript()) {
+ *     return getResourceNative(name);
+ *   } else {
+ *     if (resourceMap == null) {
+ *       resourceMap = new HashMap<String, ResourcePrototype>();
+ *       resourceMap.put("resource", resource());
+ *     }
+ *     return resourceMap.get(name);
+ *   }
+ * }
+ * private native ResourcePrototype getResourceNative(String name) /-{
  *   switch (name) {
  *     case 'resource': return th...@...::resource()();
  *   }
@@ -262,6 +274,9 @@ public abstract class AbstractClientBundleGenerator extends Generator {
       // Used by the map methods
       f.addImport(ResourcePrototype.class.getName());

+      // Used for Java resource map.
+      f.addImport(HashMap.class.getName());
+
       // The whole point of this exercise
       f.addImplementedInterface(sourceType.getQualifiedSourceName());

@@ -683,9 +698,36 @@ public abstract class AbstractClientBundleGenerator extends Generator {
     sw.outdent();
     sw.println("}");

-    // Use a switch statement as a fast map
-    sw.println("public native ResourcePrototype "
-        + "getResource(String name) /*-{");
+    // Map implementation for dev mode.
+ sw.println("private static HashMap<String, ResourcePrototype> resourceMap;");
+    sw.println("public ResourcePrototype getResource(String name) {");
+    sw.indent();
+    sw.println("if (GWT.isScript()) {");
+    sw.indent();
+    sw.println("return getResourceNative(name);");
+    sw.outdent();
+    sw.println("} else {");
+    sw.indent();
+    sw.println("if (resourceMap == null) {");
+    sw.indent();
+    sw.println("resourceMap = new HashMap<String, ResourcePrototype>();");
+    for (List<JMethod> list : taskList.values()) {
+      for (JMethod m : list) {
+        sw.println("resourceMap.put(\"" + m.getName() + "\", "
+            + m.getName() + "());");
+      }
+    }
+    sw.outdent();
+    sw.println("}");
+    sw.println("return resourceMap.get(name);");
+    sw.outdent();
+    sw.println("}");
+    sw.outdent();
+    sw.println("}");
+
+    // Use a switch statement as a fast map for script mode.
+    sw.println("private native ResourcePrototype "
+        + "getResourceNative(String name) /*-{");
     sw.indent();
     sw.println("switch (name) {");
     sw.indent();


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

Reply via email to