From: Shigeru C. <ch...@us...> - 2004-04-18 17:32:35
|
User: chiba Date: 04/04/18 10:32:29 Modified: src/main/javassist/bytecode ConstPool.java LongVector.java Log: edited for improving runtime performance. Revision Changes Path 1.7 +19 -15 javassist/src/main/javassist/bytecode/ConstPool.java Index: ConstPool.java =================================================================== RCS file: /cvsroot/jboss/javassist/src/main/javassist/bytecode/ConstPool.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ConstPool.java 8 Jan 2004 17:22:25 -0000 1.6 +++ ConstPool.java 18 Apr 2004 17:32:28 -0000 1.7 @@ -21,7 +21,7 @@ import java.io.PrintWriter; import java.io.IOException; import java.util.Map; -import java.util.Hashtable; +import java.util.HashMap; import javassist.CtClass; /** @@ -30,10 +30,9 @@ public final class ConstPool { LongVector items; int numOfItems; - Hashtable classes; - Hashtable strings; + HashMap classes; + HashMap strings; int thisClassInfo; - private static final int SIZE = 128; /** * <code>CONSTANT_Class</code> @@ -103,7 +102,11 @@ * pool table */ public ConstPool(String thisclass) { - this(); + items = new LongVector(); + numOfItems = 0; + addItem(null); // index 0 is reserved by the JVM. + classes = new HashMap(); + strings = new HashMap(); thisClassInfo = addClassInfo(thisclass); } @@ -113,17 +116,12 @@ * @param in byte stream. */ public ConstPool(DataInputStream in) throws IOException { - this(); - read(in); - } - - private ConstPool() { - items = new LongVector(SIZE); - numOfItems = 0; - addItem(null); // index 0 is reserved by the JVM. - classes = new Hashtable(); - strings = new Hashtable(); + classes = new HashMap(); + strings = new HashMap(); thisClassInfo = 0; + /* read() initializes items and numOfItems, and do addItem(null). + */ + read(in); } /** @@ -861,6 +859,12 @@ private void read(DataInputStream in) throws IOException { int n = in.readUnsignedShort(); + + int size = (n / LongVector.SIZE + 1) * LongVector.SIZE; + items = new LongVector(size); + numOfItems = 0; + addItem(null); // index 0 is reserved by the JVM. + while (--n > 0) { // index 0 is reserved by JVM int tag = readOne(in); if ((tag == LongInfo.tag) || (tag == DoubleInfo.tag)) { 1.5 +6 -1 javassist/src/main/javassist/bytecode/LongVector.java Index: LongVector.java =================================================================== RCS file: /cvsroot/jboss/javassist/src/main/javassist/bytecode/LongVector.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- LongVector.java 8 Jan 2004 17:22:25 -0000 1.4 +++ LongVector.java 18 Apr 2004 17:32:28 -0000 1.5 @@ -16,10 +16,15 @@ package javassist.bytecode; final class LongVector { + static final int SIZE = 128; private int num; private Object[] objects; private LongVector next; + public LongVector() { + this(SIZE); + } + public LongVector(int initialSize) { num = 0; objects = new Object[initialSize]; @@ -34,7 +39,7 @@ if (p.num < p.objects.length) p.objects[p.num++] = obj; else { - LongVector q = p.next = new LongVector(p.objects.length); + LongVector q = p.next = new LongVector(SIZE); q.objects[q.num++] = obj; } } |