Author: rgodfrey
Date: Thu Oct  4 13:38:04 2012
New Revision: 1394071

URL: http://svn.apache.org/viewvc?rev=1394071&view=rev
Log:
NO-JIRA: proton-j, only calculate hashCode for Binary on (first) use

Modified:
    
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java

Modified: 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java?rev=1394071&r1=1394070&r2=1394071&view=diff
==============================================================================
--- 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java
 (original)
+++ 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java
 Thu Oct  4 13:38:04 2012
@@ -31,7 +31,7 @@ public class Binary
     private final byte[] _data;
     private final int _offset;
     private final int _length;
-    private final int _hashCode;
+    private int _hashCode;
 
     public Binary(final byte[] data)
     {
@@ -40,16 +40,9 @@ public class Binary
 
     public Binary(final byte[] data, final int offset, final int length)
     {
-
         _data = data;
         _offset = offset;
         _length = length;
-        int hc = 0;
-        for (int i = 0; i < length; i++)
-        {
-            hc = 31*hc + (0xFF & data[offset + i]);
-        }
-        _hashCode = hc;
     }
 
     public ByteBuffer asByteBuffer()
@@ -59,7 +52,16 @@ public class Binary
 
     public final int hashCode()
     {
-        return _hashCode;
+        int hc = _hashCode;
+        if(hc == 0)
+        {
+            for (int i = 0; i < _length; i++)
+            {
+                hc = 31*hc + (0xFF & _data[_offset + i]);
+            }
+            _hashCode = hc;
+        }
+        return hc;
     }
 
     public final boolean equals(Object o)



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to