svn commit: r153176 - jakarta/bcel/trunk/src/java/org/apache/bcel/util/SyntheticRepository.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
Author: dbrosius
Date: Wed Feb  9 22:42:37 2005
New Revision: 153176

URL: http://svn.apache.org/viewcvs?view=rev&rev=153176
Log:
Apply Patch 32945 Make the SyntheticRepository a memory sensitive cache.

Modified:
    jakarta/bcel/trunk/src/java/org/apache/bcel/util/SyntheticRepository.java

Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/util/SyntheticRepository.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/util/SyntheticRepository.java?view=diff&r1=153175&r2=153176
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/util/SyntheticRepository.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/util/SyntheticRepository.java Wed Feb  9 22:42:37 2005
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.ref.SoftReference;
 import java.util.HashMap;
 
 import org.apache.bcel.classfile.ClassParser;
@@ -76,7 +77,7 @@
    * Store a new JavaClass instance into this Repository.
    */
   public void storeClass(JavaClass clazz) {
-    _loadedClasses.put(clazz.getClassName(), clazz);
+    _loadedClasses.put(clazz.getClassName(), new SoftReference(clazz));
     clazz.setRepository(this);
   }
 
@@ -91,7 +92,10 @@
    * Find an already defined (cached) JavaClass object by name.
    */
   public JavaClass findClass(String className) {
-    return (JavaClass)_loadedClasses.get(className);
+    SoftReference ref = (SoftReference)_loadedClasses.get(className);
+    if (ref == null)
+      return null;
+    return (JavaClass)ref.get();
   }
 
   /**
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.