From 829a336dd0bf168de7b8c66890b2d13212882190 Mon Sep 17 00:00:00 2001 From: chiba Date: Wed, 28 Apr 2010 10:26:27 +0000 Subject: [PATCH] for performance tuning git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@538 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- .../javassist/bytecode/AttributeInfo.java | 14 ++++++------- src/main/javassist/bytecode/FieldInfo.java | 12 +++++------ src/main/javassist/bytecode/LongVector.java | 14 ++++++------- src/main/javassist/bytecode/MethodInfo.java | 20 +++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/javassist/bytecode/AttributeInfo.java b/src/main/javassist/bytecode/AttributeInfo.java index 77f1686d..c7bcf149 100644 --- a/src/main/javassist/bytecode/AttributeInfo.java +++ b/src/main/javassist/bytecode/AttributeInfo.java @@ -19,7 +19,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.ListIterator; import java.util.List; import java.util.Iterator; @@ -185,7 +185,7 @@ public class AttributeInfo { out.write(info); } - static int getLength(LinkedList list) { + static int getLength(ArrayList list) { int size = 0; int n = list.size(); for (int i = 0; i < n; ++i) { @@ -196,7 +196,7 @@ public class AttributeInfo { return size; } - static AttributeInfo lookup(LinkedList list, String name) { + static AttributeInfo lookup(ArrayList list, String name) { if (list == null) return null; @@ -210,7 +210,7 @@ public class AttributeInfo { return null; // no such attribute } - static synchronized void remove(LinkedList list, String name) { + static synchronized void remove(ArrayList list, String name) { if (list == null) return; @@ -222,7 +222,7 @@ public class AttributeInfo { } } - static void writeAll(LinkedList list, DataOutputStream out) + static void writeAll(ArrayList list, DataOutputStream out) throws IOException { if (list == null) @@ -235,11 +235,11 @@ public class AttributeInfo { } } - static LinkedList copyAll(LinkedList list, ConstPool cp) { + static ArrayList copyAll(ArrayList list, ConstPool cp) { if (list == null) return null; - LinkedList newList = new LinkedList(); + ArrayList newList = new ArrayList(); int n = list.size(); for (int i = 0; i < n; ++i) { AttributeInfo attr = (AttributeInfo)list.get(i); diff --git a/src/main/javassist/bytecode/FieldInfo.java b/src/main/javassist/bytecode/FieldInfo.java index aa89dd40..f4743731 100644 --- a/src/main/javassist/bytecode/FieldInfo.java +++ b/src/main/javassist/bytecode/FieldInfo.java @@ -19,7 +19,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.List; -import java.util.LinkedList; +import java.util.ArrayList; /** * field_info structure. @@ -33,7 +33,7 @@ public final class FieldInfo { String cachedName; String cachedType; int descriptor; - LinkedList attribute; // may be null. + ArrayList attribute; // may be null. private FieldInfo(ConstPool cp) { constPool = cp; @@ -85,7 +85,7 @@ public final class FieldInfo { } void prune(ConstPool cp) { - LinkedList newAttributes = new LinkedList(); + ArrayList newAttributes = new ArrayList(); AttributeInfo invisibleAnnotations = getAttribute(AnnotationsAttribute.invisibleTag); if (invisibleAnnotations != null) { @@ -212,7 +212,7 @@ public final class FieldInfo { */ public List getAttributes() { if (attribute == null) - attribute = new LinkedList(); + attribute = new ArrayList(); return attribute; } @@ -236,7 +236,7 @@ public final class FieldInfo { */ public void addAttribute(AttributeInfo info) { if (attribute == null) - attribute = new LinkedList(); + attribute = new ArrayList(); AttributeInfo.remove(attribute, info.getName()); attribute.add(info); @@ -247,7 +247,7 @@ public final class FieldInfo { name = in.readUnsignedShort(); descriptor = in.readUnsignedShort(); int n = in.readUnsignedShort(); - attribute = new LinkedList(); + attribute = new ArrayList(); for (int i = 0; i < n; ++i) attribute.add(AttributeInfo.read(constPool, in)); } diff --git a/src/main/javassist/bytecode/LongVector.java b/src/main/javassist/bytecode/LongVector.java index d978a71e..1f76b4a0 100644 --- a/src/main/javassist/bytecode/LongVector.java +++ b/src/main/javassist/bytecode/LongVector.java @@ -19,17 +19,17 @@ final class LongVector { static final int ASIZE = 128; static final int ABITS = 7; // ASIZE = 2^ABITS static final int VSIZE = 8; - private Object[][] objects; + private ConstInfo[][] objects; private int elements; public LongVector() { - objects = new Object[VSIZE][]; + objects = new ConstInfo[VSIZE][]; elements = 0; } public LongVector(int initialSize) { int vsize = ((initialSize >> ABITS) & ~(VSIZE - 1)) + VSIZE; - objects = new Object[vsize][]; + objects = new ConstInfo[vsize][]; elements = 0; } @@ -37,25 +37,25 @@ final class LongVector { public int capacity() { return objects.length * ASIZE; } - public Object elementAt(int i) { + public ConstInfo elementAt(int i) { if (i < 0 || elements <= i) return null; return objects[i >> ABITS][i & (ASIZE - 1)]; } - public void addElement(Object value) { + public void addElement(ConstInfo value) { int nth = elements >> ABITS; int offset = elements & (ASIZE - 1); int len = objects.length; if (nth >= len) { - Object[][] newObj = new Object[len + VSIZE][]; + ConstInfo[][] newObj = new ConstInfo[len + VSIZE][]; System.arraycopy(objects, 0, newObj, 0, len); objects = newObj; } if (objects[nth] == null) - objects[nth] = new Object[ASIZE]; + objects[nth] = new ConstInfo[ASIZE]; objects[nth][offset] = value; elements++; diff --git a/src/main/javassist/bytecode/MethodInfo.java b/src/main/javassist/bytecode/MethodInfo.java index 6d819371..aae98ea6 100644 --- a/src/main/javassist/bytecode/MethodInfo.java +++ b/src/main/javassist/bytecode/MethodInfo.java @@ -18,7 +18,7 @@ package javassist.bytecode; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Map; import javassist.ClassPool; @@ -30,13 +30,13 @@ import javassist.bytecode.stackmap.MapMaker; * @see javassist.CtMethod#getMethodInfo() * @see javassist.CtConstructor#getMethodInfo() */ -public final class MethodInfo { +public class MethodInfo { ConstPool constPool; int accessFlags; int name; String cachedName; int descriptor; - LinkedList attribute; // may be null + ArrayList attribute; // may be null /** * If this value is true, Javassist maintains a StackMap attribute @@ -134,7 +134,7 @@ public final class MethodInfo { } void prune(ConstPool cp) { - LinkedList newAttributes = new LinkedList(); + ArrayList newAttributes = new ArrayList(); AttributeInfo invisibleAnnotations = getAttribute(AnnotationsAttribute.invisibleTag); @@ -283,7 +283,7 @@ public final class MethodInfo { */ public List getAttributes() { if (attribute == null) - attribute = new LinkedList(); + attribute = new ArrayList(); return attribute; } @@ -308,7 +308,7 @@ public final class MethodInfo { */ public void addAttribute(AttributeInfo info) { if (attribute == null) - attribute = new LinkedList(); + attribute = new ArrayList(); AttributeInfo.remove(attribute, info.getName()); attribute.add(info); @@ -352,7 +352,7 @@ public final class MethodInfo { public void setExceptionsAttribute(ExceptionsAttribute cattr) { removeExceptionsAttribute(); if (attribute == null) - attribute = new LinkedList(); + attribute = new ArrayList(); attribute.add(cattr); } @@ -374,7 +374,7 @@ public final class MethodInfo { public void setCodeAttribute(CodeAttribute cattr) { removeCodeAttribute(); if (attribute == null) - attribute = new LinkedList(); + attribute = new ArrayList(); attribute.add(cattr); } @@ -507,7 +507,7 @@ public final class MethodInfo { String desc2 = Descriptor.rename(desc, classnames); descriptor = destCp.addUtf8Info(desc2); - attribute = new LinkedList(); + attribute = new ArrayList(); ExceptionsAttribute eattr = src.getExceptionsAttribute(); if (eattr != null) attribute.add(eattr.copy(destCp, classnames)); @@ -522,7 +522,7 @@ public final class MethodInfo { name = in.readUnsignedShort(); descriptor = in.readUnsignedShort(); int n = in.readUnsignedShort(); - attribute = new LinkedList(); + attribute = new ArrayList(); for (int i = 0; i < n; ++i) attribute.add(AttributeInfo.read(constPool, in)); } -- 2.39.5