summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2013-08-21 09:59:40 +0300
committerVaadin Code Review <review@vaadin.com>2013-08-21 07:02:21 +0000
commitf5b67af0a4070a5f2d334aa7efa6d899f4ff60ce (patch)
tree0ee63180c6ad887af8068ac6db512afab0371af5 /client
parentc87772be9a87fe629c5c3d0077e6455261bb4762 (diff)
downloadvaadin-framework-f5b67af0a4070a5f2d334aa7efa6d899f4ff60ce.tar.gz
vaadin-framework-f5b67af0a4070a5f2d334aa7efa6d899f4ff60ce.zip
Optimize ComputedStyle.getIntProperty() (#12411)
Change-Id: I51b421e5b2c94d6b7e22a0c23bf1c8412061ef02
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ComputedStyle.java42
1 files changed, 34 insertions, 8 deletions
diff --git a/client/src/com/vaadin/client/ComputedStyle.java b/client/src/com/vaadin/client/ComputedStyle.java
index 499d9cd2d6..db8ed037bf 100644
--- a/client/src/com/vaadin/client/ComputedStyle.java
+++ b/client/src/com/vaadin/client/ComputedStyle.java
@@ -130,11 +130,11 @@ public class ComputedStyle {
}-*/;
public final int getIntProperty(String name) {
- Integer parsed = parseInt(getProperty(name));
- if (parsed != null) {
- return parsed.intValue();
- }
- return 0;
+ Profiler.enter("ComputedStyle.getIntProperty");
+ String value = getProperty(name);
+ int result = parseIntNative(value);
+ Profiler.leave("ComputedStyle.getIntProperty");
+ return result;
}
/**
@@ -177,14 +177,20 @@ public class ComputedStyle {
}
/**
- * Takes a String value e.g. "12px" and parses that to int 12.
+ * Takes a String value e.g. "12px" and parses that to Integer 12.
*
* @param String
* a value starting with a number
- * @return int the value from the string before any non-numeric characters.
- * If the value cannot be parsed to a number, returns
+ * @return Integer the value from the string before any non-numeric
+ * characters. If the value cannot be parsed to a number, returns
* <code>null</code>.
+ *
+ * @deprecated Since 7.1.4, the method {@link #parseIntNative(String)} is
+ * used internally and this method does not belong in the public
+ * API of {@link ComputedStyle}. {@link #parseInt(String)} might
+ * be removed or moved to a utility class in future versions.
*/
+ @Deprecated
public static native Integer parseInt(final String value)
/*-{
var number = parseInt(value, 10);
@@ -195,4 +201,24 @@ public class ComputedStyle {
return @java.lang.Integer::valueOf(I)(number);
}-*/;
+ /**
+ * Takes a String value e.g. "12px" and parses that to int 12.
+ *
+ * <p>
+ * This method returns 0 for <code>NaN</code>.
+ *
+ * @param String
+ * a value starting with a number
+ * @return int the value from the string before any non-numeric characters.
+ * If the value cannot be parsed to a number, returns 0.
+ */
+ private static native int parseIntNative(final String value)
+ /*-{
+ var number = parseInt(value, 10);
+ if (isNaN(number))
+ return 0;
+ else
+ return number;
+ }-*/;
+
}