From ae3821f146a28f63a175267ac056972b23186b27 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 17 Oct 2012 08:38:50 +0200 Subject: [PATCH] improve performance in native selector generators --- .../google/gwt/query/client/impl/SelectorEngine.java | 10 ++++++++++ .../gwt/query/rebind/SelectorGeneratorNative.java | 6 ++++++ .../gwt/query/rebind/SelectorGeneratorNativeIE8.java | 6 ++++++ .../gwt/query/rebind/SelectorGeneratorNativeIE9.java | 8 +++++++- 4 files changed, 29 insertions(+), 1 deletion(-) 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 elementsByTagName(String selector, + Node ctx) /*-{ + return ctx.getElementsByTagName(selector); + }-*/; + + public static native NodeList elementsByClassName(String selector, + Node ctx) /*-{ + return ctx.getElementsByClassName(selector); + }-*/; + public static NodeList veryQuickId(String id, Node ctx) { Document d = ctx.getNodeType() == Node.DOCUMENT_NODE ? ctx. 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 -- 2.39.5