src/java.base/share/classes/sun/security/util/Cache.java
changeset 47310 eca11f20586e
parent 47216 71c04702a3d5
equal deleted inserted replaced
47309:66774e1fc3a7 47310:eca11f20586e
   162      * and hashCode() contract in a way suitable for Maps and caches.
   162      * and hashCode() contract in a way suitable for Maps and caches.
   163      */
   163      */
   164     public static class EqualByteArray {
   164     public static class EqualByteArray {
   165 
   165 
   166         private final byte[] b;
   166         private final byte[] b;
   167         private volatile int hash;
   167         private int hash;
   168 
   168 
   169         public EqualByteArray(byte[] b) {
   169         public EqualByteArray(byte[] b) {
   170             this.b = b;
   170             this.b = b;
   171         }
   171         }
   172 
   172 
   173         public int hashCode() {
   173         public int hashCode() {
   174             int h = hash;
   174             int h = hash;
   175             if (h == 0) {
   175             if (h == 0 && b.length > 0) {
   176                 h = b.length + 1;
   176                 hash = h = Arrays.hashCode(b);
   177                 for (int i = 0; i < b.length; i++) {
       
   178                     h += (b[i] & 0xff) * 37;
       
   179                 }
       
   180                 hash = h;
       
   181             }
   177             }
   182             return h;
   178             return h;
   183         }
   179         }
   184 
   180 
   185         public boolean equals(Object obj) {
   181         public boolean equals(Object obj) {