changeset 926:de1d02ad2d1d

6799689: Make sun.misc.FloatingDecimal.hexFloatPattern static field initialized lazily Summary: Lazily initialize the hexFloatPattern static field Reviewed-by: darcy
author mchung
date Fri, 27 Feb 2009 13:43:48 -0800
parents 4f0b6455a977
children 0da45c759116
files src/share/classes/sun/misc/FloatingDecimal.java
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/misc/FloatingDecimal.java	Thu Feb 26 18:51:57 2009 -0800
+++ b/src/share/classes/sun/misc/FloatingDecimal.java	Fri Feb 27 13:43:48 2009 -0800
@@ -1867,10 +1867,16 @@
      * Grammar is compatible with hexadecimal floating-point constants
      * described in section 6.4.4.2 of the C99 specification.
      */
-    private static Pattern hexFloatPattern = Pattern.compile(
+    private static Pattern hexFloatPattern = null;
+    private static synchronized Pattern getHexFloatPattern() {
+        if (hexFloatPattern == null) {
+           hexFloatPattern = Pattern.compile(
                    //1           234                   56                7                   8      9
                     "([-+])?0[xX](((\\p{XDigit}+)\\.?)|((\\p{XDigit}*)\\.(\\p{XDigit}+)))[pP]([-+])?(\\p{Digit}+)[fFdD]?"
                     );
+        }
+        return hexFloatPattern;
+    }
 
     /*
      * Convert string s to a suitable floating decimal; uses the
@@ -1880,7 +1886,7 @@
    static FloatingDecimal parseHexString(String s) {
         // Verify string is a member of the hexadecimal floating-point
         // string language.
-        Matcher m = hexFloatPattern.matcher(s);
+        Matcher m = getHexFloatPattern().matcher(s);
         boolean validInput = m.matches();
 
         if (!validInput) {