]> source.dussan.org Git - javassist.git/commitdiff
added detach() in CtClass, which is necessary so that some people who
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 27 Apr 2004 16:01:40 +0000 (16:01 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 27 Apr 2004 16:01:40 +0000 (16:01 +0000)
deal with a large number of classes can get better performance.

git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@95 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/ClassPool.java
src/main/javassist/CtClass.java
src/main/javassist/CtClassType.java

index bc2a2d80b070c4d44ca8658719905ce0f1e8f124..054b56e1a31e9ba0c7d1cb8f00e9032be73a681b 100644 (file)
@@ -167,8 +167,8 @@ public class ClassPool {
      * @see #getCached(String)
      * @see #cacheCtClass(String,CtClass)
      */
-    protected void removeCached(String classname) {
-        classes.remove(classname);
+    protected CtClass removeCached(String classname) {
+        return (CtClass)classes.remove(classname);
     }
 
     /**
index 41fa0dfe678095ed3bd17101194817a6c92e1926..c5c86ba531355f38899f5a7612373120052abeb0 100644 (file)
@@ -865,6 +865,21 @@ public abstract class CtClass {
         return getClassPool().forName(name);
     }
 
+    /**
+     * Removes this <code>CtClass</code> from the <code>ClassPool</code>.
+     *
+     * <p>If needed,
+     * the <code>ClassPool</code> will read the class file again
+     * and constructs another <code>CtClass</code> object representing
+     * the same class.
+     */
+    public void detach() {
+        ClassPool cp = getClassPool();
+        CtClass obj = cp.removeCached(getName());
+        if (obj != this)
+            cp.cacheCtClass(getName(), obj);
+    }
+
     /**
      * Converts this class to a class file.
      * Once this method is called, further modifications are not
index c1594c41ccbc5a6020f8c79cefe3289f7051bdad..d206b62fc62fa21385b5f41f67e2516b9f1ac95f 100644 (file)
@@ -783,7 +783,7 @@ class CtClassType extends CtClass {
                 cf.write(out);
                 out.flush();
             }
-            else
+            else 
                 classPool.writeClassfile(getName(), out);
 
             wasFrozen = true;