Reviewers: knorton,
Description:
Cache Document.get for DevMode. Kills thousands of JSNI calls.
Please review this at http://gwt-code-reviews.appspot.com/1338806/show
Affected files:
M user/src/com/google/gwt/dom/client/Document.java
Index: user/src/com/google/gwt/dom/client/Document.java
===================================================================
--- user/src/com/google/gwt/dom/client/Document.java (revision 9659)
+++ user/src/com/google/gwt/dom/client/Document.java (working copy)
@@ -15,6 +15,8 @@
*/
package com.google.gwt.dom.client;
+import com.google.gwt.core.client.GWT;
+
/**
* A Document is the root of the HTML hierarchy and holds the entire
content.
* Besides providing access to the hierarchy, it also provides some
convenience
@@ -23,12 +25,30 @@
public class Document extends Node {
/**
+ * We cache Document.nativeGet() in DevMode, because crossing the JSNI
+ * boundary thousands of times just to read a constant value is slow.
+ */
+ private static Document doc;
+
+ /**
* Gets the default document. This is the document in which the module is
* running.
*
* @return the default document
*/
- public static native Document get() /*-{
+ public static Document get() {
+ if (GWT.isScript()) {
+ return nativeGet();
+ }
+
+ // No need to be MT-safe. Single-threaded JS code.
+ if (doc == null) {
+ doc = nativeGet();
+ }
+ return doc;
+ }
+
+ private static native Document nativeGet() /*-{
return $doc;
}-*/;
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors