aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2012-10-17 08:38:50 +0200
committerManolo Carrasco <manolo@apache.org>2012-10-17 08:38:50 +0200
commitae3821f146a28f63a175267ac056972b23186b27 (patch)
tree8d50d53e4fc7d4d6b40479afcbd521e74a4c9029
parent1436975005f22aa27d1a42ae3e3d40d42c9c2978 (diff)
downloadgwtquery-ae3821f146a28f63a175267ac056972b23186b27.tar.gz
gwtquery-ae3821f146a28f63a175267ac056972b23186b27.zip
improve performance in native selector generators
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java10
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java6
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java6
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java8
4 files changed, 29 insertions, 1 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java
index fe793fd9..def31d91 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java
@@ -61,6 +61,16 @@ public class SelectorEngine implements HasSelector {
return ctx.querySelectorAll(selector);
}-*/;
+ public static native NodeList<Element> elementsByTagName(String selector,
+ Node ctx) /*-{
+ return ctx.getElementsByTagName(selector);
+ }-*/;
+
+ public static native NodeList<Element> elementsByClassName(String selector,
+ Node ctx) /*-{
+ return ctx.getElementsByClassName(selector);
+ }-*/;
+
public static NodeList<Element> veryQuickId(String id, Node ctx) {
Document d = ctx.getNodeType() == Node.DOCUMENT_NODE
? ctx.<Document> cast() : ctx.getOwnerDocument();
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java
index 554809a7..b09a07dd 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java
@@ -36,6 +36,12 @@ public class SelectorGeneratorNative extends SelectorGeneratorCssToXPath {
if (selector.matches("#[\\w\\-]+")) {
sw.println("return "
+ wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";");
+ } else if (selector.equals("*") || selector.matches("[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "elementsByTagName(\"" + selector + "\", root)") + ";");
+ } else if (selector.matches("\\.[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "elementsByClassName(\"" + selector.substring(1) + "\", root)") + ";");
} else if (selector.contains("!=")) {
sw.println("return "
+ wrap(method, "querySelectorAll(\""
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java
index b97cd899..4ec3f1c6 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java
@@ -35,6 +35,12 @@ public class SelectorGeneratorNativeIE8 extends SelectorGeneratorJS {
if (selector.matches("#[\\w\\-]+")) {
sw.println("return "
+ wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";");
+ } else if (selector.equals("*") || selector.matches("[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "elementsByTagName(\"" + selector + "\", root)") + ";");
+ } else if (selector.matches("\\.[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "elementsByClassName(\"" + selector.substring(1) + "\", root)") + ";");
} else if (selector.matches(SelectorEngineNativeIE8.NATIVE_EXCEPTIONS_REGEXP)) {
super.generateMethodBody(sw, method, treeLogger, hasContext);
} else {
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java
index ae76e4e9..af3a690d 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java
@@ -35,6 +35,12 @@ public class SelectorGeneratorNativeIE9 extends SelectorGeneratorJS {
if (selector.matches("#[\\w\\-]+")) {
sw.println("return "
+ wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";");
+ } else if (selector.equals("*") || selector.matches("[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "elementsByTagName(\"" + selector + "\", root)") + ";");
+ } else if (selector.matches("\\.[\\w\\-]+")) {
+ sw.println("return "
+ + wrap(method, "elementsByClassName(\"" + selector.substring(1) + "\", root)") + ";");
} else if (selector.matches(SelectorEngineNative.NATIVE_EXCEPTIONS_REGEXP)) {
super.generateMethodBody(sw, method, treeLogger, hasContext);
} else {
@@ -45,7 +51,7 @@ public class SelectorGeneratorNativeIE9 extends SelectorGeneratorJS {
@Override
protected String getImplSuffix() {
- return "IE8" + super.getImplSuffix();
+ return "IE9" + super.getImplSuffix();
}
@Override