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.
This commit is contained in:
Dmitriy Dumanskiy 2017-01-18 18:16:49 +02:00 committed by Norman Maurer
parent fac0ca8319
commit 141554f5d1

View File

@ -20,7 +20,6 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; 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. * 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; return def;
} }
private static final Pattern INTEGER_PATTERN = Pattern.compile("-?[0-9]+");
/** /**
* Returns the value of the Java system property with the specified * Returns the value of the Java system property with the specified
* {@code key}, while falling back to the specified default value if * {@code key}, while falling back to the specified default value if
@ -140,13 +137,11 @@ public final class SystemPropertyUtil {
return def; return def;
} }
value = value.trim().toLowerCase(); value = value.trim();
if (INTEGER_PATTERN.matcher(value).matches()) { try {
try { return Integer.parseInt(value);
return Integer.parseInt(value); } catch (Exception e) {
} catch (Exception e) { // Ignore
// Ignore
}
} }
logger.warn( logger.warn(
@ -172,13 +167,11 @@ public final class SystemPropertyUtil {
return def; return def;
} }
value = value.trim().toLowerCase(); value = value.trim();
if (INTEGER_PATTERN.matcher(value).matches()) { try {
try { return Long.parseLong(value);
return Long.parseLong(value); } catch (Exception e) {
} catch (Exception e) { // Ignore
// Ignore
}
} }
logger.warn( logger.warn(