geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1396337 - /geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Artifact.java
Date Tue, 09 Oct 2012 21:29:18 GMT
Author: gawor
Date: Tue Oct  9 21:29:18 2012
New Revision: 1396337

URL: http://svn.apache.org/viewvc?rev=1396337&view=rev
Log:
minor optimization: cache hashCode value for Artifact object

Modified:
    geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Artifact.java

Modified: geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Artifact.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Artifact.java?rev=1396337&r1=1396336&r2=1396337&view=diff
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Artifact.java
(original)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/Artifact.java
Tue Oct  9 21:29:18 2012
@@ -30,6 +30,8 @@ public class Artifact implements Compara
     private final String artifactId;
     private final Version version;
     private final String type;
+    
+    private transient int hashCode;
 
     public Artifact(String groupId, String artifactId, String version, String type) {
         this(groupId, artifactId, version == null ? null : new Version(version), type, true);
@@ -139,12 +141,15 @@ public class Artifact implements Compara
     }
 
     public int hashCode() {
-        int result;
-        result = (groupId != null ? groupId.hashCode() : 0);
-        result = 29 * result + (artifactId != null? artifactId.hashCode() : 0);
-        result = 29 * result + (version != null ? version.hashCode() : 0);
-        result = 29 * result + (type != null ? type.hashCode() : 0);
-        return result;
+        if (hashCode == 0) {
+            int result;
+            result = (groupId != null ? groupId.hashCode() : 0);
+            result = 29 * result + (artifactId != null? artifactId.hashCode() : 0);
+            result = 29 * result + (version != null ? version.hashCode() : 0);
+            result = 29 * result + (type != null ? type.hashCode() : 0);
+            hashCode = result;
+        }
+        return hashCode;
     }
 
     public String toString() {



Mime
View raw message