harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r413349 - /incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java
Date Sat, 10 Jun 2006 18:30:32 GMT
Author: archie
Date: Sat Jun 10 11:30:32 2006
New Revision: 413349

URL: http://svn.apache.org/viewvc?rev=413349&view=rev
Log:
Simplify String.intern(): WeakHashMap already wraps keys in weak references.

Modified:
    incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java

Modified: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java?rev=413349&r1=413348&r2=413349&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java
(original)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java
Sat Jun 10 11:30:32 2006
@@ -81,7 +81,6 @@
 import java.util.Locale;
 import java.util.regex.Pattern;
 import java.util.WeakHashMap;
-import java.lang.ref.WeakReference;
 
 /**
  * @com.intel.drl.spec_ref 
@@ -1328,22 +1327,16 @@
         }
     }
 
-    private static WeakHashMap strings = new WeakHashMap(4096);
+    private static WeakHashMap internedStrings = new WeakHashMap(4096);
 
     public String intern() {
-        synchronized (strings) {
-            WeakReference ref =
-                (WeakReference) strings.get(this);
-            String str = null;
-
-            if (ref != null) {
-                str = (String) ref.get();
+        synchronized (internedStrings) {
+            String i = (String)internedStrings.get(this);
+            if (i == null) {
+		internedStrings.put(this, this);
+                i = this;
             }
-
-            if (str != null) return str;
-
-            strings.put(this, new WeakReference(this));
-            return this;
+            return i;
         }
     }
 }



Mime
View raw message