Changeset 7973f2e


Ignore:
Timestamp:
Aug 26, 2009 10:17:29 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
93d366fe
Parents:
bb14fa0
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/DataHelper.java

    rbb14fa0 r7973f2e  
    799799     */
    800800    public static int hashCode(byte b[]) {
     801        // Java 5 now has its own method, and the old way
     802        // is horrible for arrays smaller than 32.
     803        // otoh, for sizes >> 32, java's method may be too slow
    801804        int rv = 0;
    802805        if (b != null) {
    803             for (int i = 0; i < b.length && i < 32; i++)
    804                 rv += (b[i] << i);
     806            if (b.length <= 32) {
     807                rv = Arrays.hashCode(b);
     808            } else {
     809                for (int i = 0; i < b.length && i < 32; i++)
     810                    rv ^= (b[i] << i);  // xor better than + in tests
     811            }
    805812        }
    806813        return rv;
     814
    807815    }
    808816
Note: See TracChangeset for help on using the changeset viewer.