From: Henri Sara Date: Wed, 21 Aug 2013 06:59:40 +0000 (+0300) Subject: Optimize ComputedStyle.getIntProperty() (#12411) X-Git-Tag: 7.1.4~30 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f5b67af0a4070a5f2d334aa7efa6d899f4ff60ce;p=vaadin-framework.git Optimize ComputedStyle.getIntProperty() (#12411) Change-Id: I51b421e5b2c94d6b7e22a0c23bf1c8412061ef02 --- 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 * null. + * + * @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. + * + *

+ * This method returns 0 for NaN. + * + * @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; + }-*/; + }