From 00da5fd6edd87dbcb273eca3050991e22dec324d Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 23 Jun 2008 04:01:11 +0000 Subject: [PATCH] PERFORMANCE: cache field lookups --- .../apache/bcel/classfile/ConstantPool.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java index 31157a48d..d9e36ca18 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java @@ -1,13 +1,15 @@ package org.aspectj.apache.bcel.classfile; -import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.*; - -import java.io.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; import java.util.HashMap; -import java.util.List; import java.util.Map; +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.ArrayType; +import org.aspectj.apache.bcel.generic.ObjectType; + /** * This class represents the constant pool, i.e., a table of constants, of * a parsed classfile. It may contain null references, due to the JVM @@ -20,6 +22,7 @@ public class ConstantPool implements Node { private Map utf8Cache = new HashMap(); private Map methodCache = new HashMap(); + private Map fieldCache = new HashMap(); public int getSize() { return poolSize; } @@ -324,6 +327,9 @@ public class ConstantPool implements Node { public int lookupFieldref(String searchClassname, String searchFieldname, String searchSignature) { searchClassname = searchClassname.replace('.','/'); + String k = new StringBuffer().append(searchClassname).append(searchFieldname).append(searchSignature).toString(); + Integer pos = (Integer) fieldCache.get(k); + if (pos!=null) return pos.intValue(); for (int i=1;i