harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r644658 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200: ./ bytecode/
Date Fri, 04 Apr 2008 09:46:05 GMT
Author: sjanuary
Date: Fri Apr  4 02:46:02 2008
New Revision: 644658

URL: http://svn.apache.org/viewvc?rev=644658&view=rev
Log:
Apply second patch for HARMONY-5682 ([classlib][pack200] Sped up hashCode and removed dead
getCpAll())

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPConstant.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java?rev=644658&r1=644657&r2=644658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java
Fri Apr  4 02:46:02 2008
@@ -290,47 +290,4 @@
             throw new Error("Get value incomplete");
         }
     }
-
-    protected ConstantPoolEntry cachedCpAll[] = {};
-    public ConstantPoolEntry[] getCpAll() throws Pack200Exception {
-        if(cachedCpAll.length == 0) {
-        	ArrayList cpAll = new ArrayList();
-        	// TODO: this is 1.5-specific. Try to get rid
-        	// of it.
-        	for(int index=0; index < bands.getCpUTF8().length; index++) {
-        		cpAll.add(getConstantPoolEntry(UTF_8, index));
-        	}
-        	for(int index=0; index < bands.getCpInt().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_INT, index));
-        	}
-        	for(int index=0; index < bands.getCpFloat().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_FLOAT, index));
-        	}
-        	for(int index=0; index < bands.getCpLong().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_LONG, index));
-        	}
-        	for(int index=0; index < bands.getCpDouble().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_DOUBLE, index));
-        	}
-        	for(int index=0; index < bands.getCpString().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_STRING, index));
-        	}
-        	for(int index=0; index < bands.getCpClass().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_CLASS, index));
-        	}
-        	for(int index=0; index < bands.getCpFieldClass().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_FIELD, index));
-        	}
-        	for(int index=0; index < bands.getCpMethodClass().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_METHOD, index));
-        	}
-        	for(int index=0; index < bands.getCpIMethodClass().length; index++) {
-        		cpAll.add(getConstantPoolEntry(CP_IMETHOD, index));
-        	}
-        	ConstantPoolEntry[] result = new ConstantPoolEntry[cpAll.size()];
-        	cpAll.toArray(result);
-        	cachedCpAll = result;
-        }
-        return cachedCpAll;
-    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java?rev=644658&r1=644657&r2=644658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java
Fri Apr  4 02:46:02 2008
@@ -19,19 +19,27 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 
-
 public class CPClass extends ConstantPoolEntry {
+
 	private int index;
 
 	public String name;
 
-	private CPUTF8 utf8;
+	private final CPUTF8 utf8;
 
+	/**
+	 * Creates a new CPClass
+	 * @param name
+	 * @throws NullPointerException if name is null
+	 */
     public CPClass(CPUTF8 name) {
 		super(ConstantPoolEntry.CP_Class);
 		this.name = name.underlyingString();
 		this.domain = ClassConstantPool.DOMAIN_CLASSREF;
 		this.utf8 = name;
+		if(name == null) {
+            throw new NullPointerException("Null arguments are not allowed");
+		}
 	}
 
     public boolean equals(Object obj) {
@@ -42,17 +50,7 @@
 		if (this.getClass() != obj.getClass())
 			return false;
 		final CPClass other = (CPClass) obj;
-		if (name == null) {
-			if (other.name != null)
-				return false;
-		} else if (!name.equals(other.name))
-			return false;
-		if (utf8 == null) {
-			if (other.utf8 != null)
-				return false;
-		} else if (!utf8.equals(other.utf8))
-			return false;
-		return true;
+		return utf8.equals(other.utf8);
 	}
 
 	protected ClassFileEntry[] getNestedClassFileEntries() {
@@ -61,11 +59,7 @@
 
 
 	public int hashCode() {
-		final int PRIME = 31;
-		int result = 1;
-		result = PRIME * result + ((name == null) ? 0 : name.hashCode());
-		result = PRIME * result + ((utf8 == null) ? 0 : utf8.hashCode());
-		return result;
+		return utf8.hashCode();
 	}
 
 	protected void resolve(ClassConstantPool pool) {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPConstant.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPConstant.java?rev=644658&r1=644657&r2=644658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPConstant.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPConstant.java
Fri Apr  4 02:46:02 2008
@@ -19,13 +19,21 @@
 
 public abstract class CPConstant extends ConstantPoolEntry {
 
-	private Object value;
+	private final Object value;
 
+	/**
+	 * Create a new CPConstant
+	 * @param tag
+	 * @param value
+	 * @throws NullPointerException if value is null
+	 */
 	public CPConstant(byte tag, Object value) {
 		super(tag);
 		this.value = value;
+		if (value == null) {
+		    throw new NullPointerException("Null arguments are not allowed");
+		}
 	}
-
 
 	public boolean equals(Object obj) {
 		if (this == obj)

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java?rev=644658&r1=644657&r2=644658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java
Fri Apr  4 02:46:02 2008
@@ -18,7 +18,7 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -28,14 +28,25 @@
 	short flags;
 	CPUTF8 name;
 	transient int nameIndex;
-	private CPUTF8 descriptor;
+	private final CPUTF8 descriptor;
 	transient int descriptorIndex;
 
+	/**
+	 * Create a new CPMember
+	 * @param name
+	 * @param descriptor
+	 * @param flags
+	 * @param attributes
+	 * @throws NullPointerException if name or descriptor is null
+	 */
 	public CPMember(CPUTF8 name, CPUTF8 descriptor, long flags, List attributes) {
 		this.name = name;
         this.descriptor = descriptor;
         this.flags = (short) flags;
-		this.attributes = (attributes == null ? new ArrayList() : attributes);
+		this.attributes = (attributes == null ? Collections.EMPTY_LIST : attributes);
+		if(name == null || descriptor == null) {
+            throw new NullPointerException("Null arguments are not allowed");
+		}
 	}
 
 	protected ClassFileEntry[] getNestedClassFileEntries() {
@@ -66,10 +77,10 @@
 	public int hashCode() {
 		final int PRIME = 31;
 		int result = 1;
-		result = PRIME * result + ((attributes == null) ? 0 : attributes.hashCode());
-		result = PRIME * result + ((descriptor == null) ? 0 : descriptor.hashCode());
+		result = PRIME * result + attributes.hashCode();
+		result = PRIME * result + descriptor.hashCode();
 		result = PRIME * result + flags;
-		result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+		result = PRIME * result + name.hashCode();
 		return result;
 	}
 
@@ -81,22 +92,13 @@
 		if (getClass() != obj.getClass())
 			return false;
 		final CPMember other = (CPMember) obj;
-		if (attributes == null) {
-			if (other.attributes != null)
-				return false;
-		} else if (!attributes.equals(other.attributes))
+		if (!attributes.equals(other.attributes))
 			return false;
-		if (descriptor == null) {
-			if (other.descriptor != null)
-				return false;
-		} else if (!descriptor.equals(other.descriptor))
+		if (!descriptor.equals(other.descriptor))
 			return false;
 		if (flags != other.flags)
 			return false;
-		if (name == null) {
-			if (other.name != null)
-				return false;
-		} else if (!name.equals(other.name))
+		if (!name.equals(other.name))
 			return false;
 		return true;
 	}

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java?rev=644658&r1=644657&r2=644658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
Fri Apr  4 02:46:02 2008
@@ -31,11 +31,21 @@
 
 	transient int nameIndex;
 
+	/**
+	 * Create a new CPNameAndType
+	 * @param name
+	 * @param descriptor
+	 * @param domain
+	 * @throws NullPointerException if name or descriptor is null
+	 */
 	public CPNameAndType(CPUTF8 name, CPUTF8 descriptor, int domain) {
 		super(ConstantPoolEntry.CP_NameAndType);
 		this.name = name;
 		this.descriptor = descriptor;
         this.domain = domain;
+        if(name == null || descriptor == null) {
+            throw new NullPointerException("Null arguments are not allowed");
+        }
 	}
 
 	protected ClassFileEntry[] getNestedClassFileEntries() {
@@ -67,8 +77,8 @@
 	public int hashCode() {
 		final int PRIME = 31;
 		int result = 1;
-		result = PRIME * result + ((descriptor == null) ? 0 : descriptor.hashCode());
-		result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+		result = PRIME * result + descriptor.hashCode();
+		result = PRIME * result + name.hashCode();
 		return result;
 	}
 
@@ -81,15 +91,9 @@
 		if (getClass() != obj.getClass())
 			return false;
 		final CPNameAndType other = (CPNameAndType) obj;
-		if (descriptor == null) {
-			if (other.descriptor != null)
-				return false;
-		} else if (!descriptor.equals(other.descriptor))
+		if (!descriptor.equals(other.descriptor))
 			return false;
-		if (name == null) {
-			if (other.name != null)
-				return false;
-		} else if (!name.equals(other.name))
+		if (!name.equals(other.name))
 			return false;
 		return true;
 	}

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java?rev=644658&r1=644657&r2=644658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
Fri Apr  4 02:46:02 2008
@@ -27,10 +27,20 @@
 	protected CPNameAndType nameAndType;
 	transient int nameAndTypeIndex;
 
+    /**
+	 * Create a new CPRef
+	 * @param type
+	 * @param className
+	 * @param descriptor
+	 * @throws NullPointerException if descriptor or className is null
+	 */
 	public CPRef(byte type, CPClass className, CPNameAndType descriptor) {
 		super(type);
 		this.className = className;
 		this.nameAndType = descriptor;
+		if(descriptor == null || className == null) {
+            throw new NullPointerException("Null arguments are not allowed");
+		}
 	}
 
 	public boolean equals(Object obj) {
@@ -44,15 +54,9 @@
 		    return false;
 		}
 		final CPRef other = (CPRef) obj;
-		if (className == null) {
-			if (other.className != null)
-				return false;
-		} else if (!className.equals(other.className))
+		if (!className.equals(other.className))
 			return false;
-		if (nameAndType == null) {
-			if (other.nameAndType != null)
-				return false;
-		} else if (!nameAndType.equals(other.nameAndType))
+		if (!nameAndType.equals(other.nameAndType))
 			return false;
 		return true;
 	}
@@ -65,13 +69,8 @@
 	}
 
 	public int hashCode() {
-		final int PRIME = 31;
-		int result = 1;
-		result = PRIME * result
-				+ ((className == null) ? 0 : className.hashCode());
-		result = PRIME * result
-				+ ((nameAndType == null) ? 0 : nameAndType.hashCode());
-		return result;
+		final int PRIME = 37;
+		return (PRIME * className.hashCode()) + nameAndType.hashCode();
 	}
 
 	protected void resolve(ClassConstantPool pool) {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java?rev=644658&r1=644657&r2=644658&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java
Fri Apr  4 02:46:02 2008
@@ -22,8 +22,14 @@
 
 public class CPUTF8 extends ConstantPoolEntry {
 
-    private String utf8;
+    private final String utf8;
 
+    /**
+     * Creates a new CPUTF8 instance
+     * @param utf8
+     * @param domain
+     * @throws NullPointerException if utf8 is null
+     */
     public CPUTF8(String utf8, int domain) {
 		super(ConstantPoolEntry.CP_UTF8);
 		this.utf8 = utf8;
@@ -31,6 +37,9 @@
         if(domain == ClassConstantPool.DOMAIN_UNDEFINED) {
             throw new RuntimeException();
         }
+        if(utf8 == null) {
+            throw new NullPointerException("Null arguments are not allowed");
+        }
 	}
 
 	public boolean equals(Object obj) {
@@ -41,19 +50,12 @@
 		if (this.getClass() != obj.getClass())
 			return false;
 		final CPUTF8 other = (CPUTF8) obj;
-		if (utf8 == null) {
-			if (other.utf8 != null)
-				return false;
-		} else if (!utf8.equals(other.utf8))
-			return false;
-		return true;
+		return utf8.equals(other.utf8);
 	}
 
 	public int hashCode() {
 		final int PRIME = 31;
-		int result = 1;
-		result = PRIME * result + ((utf8 == null) ? 0 : utf8.hashCode());
-		return result;
+		return PRIME + utf8.hashCode();
 	}
 
 	public String toString() {
@@ -64,11 +66,7 @@
 		byte[] bytes;
 		try {
 			// TODO Check that this is the right UTF-8 for bytes
-			if (utf8 == null) {
-				bytes = new byte[0];
-			} else {
-				bytes = utf8.getBytes("UTF-8");
-			}
+			bytes = utf8.getBytes("UTF-8");
 		} catch (UnsupportedEncodingException e) {
 			throw new RuntimeException("Couldn't convert string " + utf8
 					+ " to UTF-8");



Mime
View raw message