From 141554f5d15d0014eccefa8de42388bda1bfa255 Mon Sep 17 00:00:00 2001 From: Dmitriy Dumanskiy Date: Wed, 18 Jan 2017 18:16:49 +0200 Subject: [PATCH] Removed unnecessary pattern matching during number paring and unnecessary toLowerCase() invocation. Motivation: Pattern matching not necessary for number parsing. Modification: Removed pattern matching for number parsing and removed unnecessary toLowerCase() operation. Result: No static variable with pattern, removed unnecessary matching operation and toLowerCase() operation. --- .../util/internal/SystemPropertyUtil.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/io/netty/util/internal/SystemPropertyUtil.java b/common/src/main/java/io/netty/util/internal/SystemPropertyUtil.java index 5f20b2e563..a48f150862 100644 --- a/common/src/main/java/io/netty/util/internal/SystemPropertyUtil.java +++ b/common/src/main/java/io/netty/util/internal/SystemPropertyUtil.java @@ -20,7 +20,6 @@ import io.netty.util.internal.logging.InternalLoggerFactory; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.regex.Pattern; /** * A collection of utility methods to retrieve and parse the values of the Java system properties. @@ -123,8 +122,6 @@ public final class SystemPropertyUtil { return def; } - private static final Pattern INTEGER_PATTERN = Pattern.compile("-?[0-9]+"); - /** * Returns the value of the Java system property with the specified * {@code key}, while falling back to the specified default value if @@ -140,13 +137,11 @@ public final class SystemPropertyUtil { return def; } - value = value.trim().toLowerCase(); - if (INTEGER_PATTERN.matcher(value).matches()) { - try { - return Integer.parseInt(value); - } catch (Exception e) { - // Ignore - } + value = value.trim(); + try { + return Integer.parseInt(value); + } catch (Exception e) { + // Ignore } logger.warn( @@ -172,13 +167,11 @@ public final class SystemPropertyUtil { return def; } - value = value.trim().toLowerCase(); - if (INTEGER_PATTERN.matcher(value).matches()) { - try { - return Long.parseLong(value); - } catch (Exception e) { - // Ignore - } + value = value.trim(); + try { + return Long.parseLong(value); + } catch (Exception e) { + // Ignore } logger.warn(