forked from I2P_Developers/i2p.i2p
i2psnark: Cache length of metainfo
This commit is contained in:
@ -49,7 +49,7 @@ class MagnetState {
|
||||
infohash = iHash;
|
||||
if (meta != null) {
|
||||
metainfo = meta;
|
||||
initialize(meta.getInfoBytes().length);
|
||||
initialize(meta.getInfoBytesLength());
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public class MetaInfo
|
||||
private final String created_by;
|
||||
private final long creation_date;
|
||||
private Map<String, BEValue> infoMap;
|
||||
private int infoBytesLength;
|
||||
|
||||
/**
|
||||
* Called by Storage when creating a new torrent from local data
|
||||
@ -622,11 +623,27 @@ public class MetaInfo
|
||||
return BEncoder.bencode(m);
|
||||
}
|
||||
|
||||
/** @since 0.8.4 */
|
||||
/**
|
||||
* Side effect: Caches infoBytesLength.
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public synchronized byte[] getInfoBytes() {
|
||||
if (infoMap == null)
|
||||
createInfoMap();
|
||||
return BEncoder.bencode(infoMap);
|
||||
byte[] rv = BEncoder.bencode(infoMap);
|
||||
infoBytesLength = rv.length;
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* The size of getInfoBytes().
|
||||
* Cached.
|
||||
* @since 0.9.48
|
||||
*/
|
||||
public synchronized int getInfoBytesLength() {
|
||||
if (infoBytesLength > 0)
|
||||
return infoBytesLength;
|
||||
return getInfoBytes().length;
|
||||
}
|
||||
|
||||
/** @return an unmodifiable view of the Map */
|
||||
|
@ -290,7 +290,7 @@ public class Peer implements Comparable<Peer>
|
||||
if ((options & OPTION_EXTENSION) != 0) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Peer supports extensions, sending reply message");
|
||||
int metasize = metainfo != null ? metainfo.getInfoBytes().length : -1;
|
||||
int metasize = metainfo != null ? metainfo.getInfoBytesLength() : -1;
|
||||
boolean pexAndMetadata = metainfo == null || !metainfo.isPrivate();
|
||||
boolean dht = util.getDHT() != null;
|
||||
boolean comment = util.utCommentsEnabled();
|
||||
|
Reference in New Issue
Block a user