Revision: 9746
Author: [email protected]
Date: Wed Feb 16 13:59:58 2011
Log: Cache Document.get for DevMode. Kills thousands of JSNI calls.
Review at http://gwt-code-reviews.appspot.com/1338806
http://code.google.com/p/google-web-toolkit/source/detail?r=9746
Modified:
/trunk/user/src/com/google/gwt/dom/client/Document.java
=======================================
--- /trunk/user/src/com/google/gwt/dom/client/Document.java Fri Jan 28
12:43:16 2011
+++ /trunk/user/src/com/google/gwt/dom/client/Document.java Wed Feb 16
13:59:58 2011
@@ -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
@@ -22,13 +24,31 @@
*/
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