Changeset 8682e7d


Ignore:
Timestamp:
Nov 27, 2009 4:29:15 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2db7c2b
Parents:
ea07471
Message:

cache the hash of the Hash

File:
1 edited

Legend:

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

    rea07471 r8682e7d  
    3333    private volatile String _base64ed;
    3434    private /* FIXME final FIXME */ Map _xorCache;
     35    private int _cachedHashCode;
    3536
    3637    public final static int HASH_LENGTH = 32;
     
    5556        _stringified = null;
    5657        _base64ed = null;
     58        _cachedHashCode = calcHashCode();
    5759    }
    5860
     
    134136        int read = read(in, _data);
    135137        if (read != HASH_LENGTH) throw new DataFormatException("Not enough bytes to read the hash");
     138        _cachedHashCode = calcHashCode();
    136139    }
    137140   
     
    151154    @Override
    152155    public int hashCode() {
     156        return _cachedHashCode;
     157    }
     158
     159    /** a Hash is a hash, so just use the first 4 bytes for speed */
     160    private int calcHashCode() {
    153161        int rv = 0;
    154162        if (_data != null) {
Note: See TracChangeset for help on using the changeset viewer.