From: chiba Date: Tue, 27 Apr 2004 16:01:40 +0000 (+0000) Subject: added detach() in CtClass, which is necessary so that some people who X-Git-Tag: rel_3_17_1_ga~516 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b25388461bd32f33f3a4a188b5eeae957cbb080d;p=javassist.git added detach() in CtClass, which is necessary so that some people who 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 --- diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index bc2a2d80..054b56e1 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -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); } /** diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 41fa0dfe..c5c86ba5 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -865,6 +865,21 @@ public abstract class CtClass { return getClassPool().forName(name); } + /** + * Removes this CtClass from the ClassPool. + * + *

If needed, + * the ClassPool will read the class file again + * and constructs another CtClass 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 diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index c1594c41..d206b62f 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -783,7 +783,7 @@ class CtClassType extends CtClass { cf.write(out); out.flush(); } - else + else classPool.writeClassfile(getName(), out); wasFrozen = true;