freenet/fred — pull request #302 by bertm (2014-11-03 12:16:32+00:00)
Title: Packet handling: simple efficiency improvements

This pull request is the squashed equivalent of #298, complete with standards-conformant commit message.

PacketThrottle:
* add method to report multiple lost packets, so we can call that
instead of iterating over notifyOfPacketLost. This replaces the
original notifyOfPacketLost that is now no longer used

NewPacketFormatKeyContext:
* reduce the operations inside a synchronized(){} block to a bare
minimum
* only keep track of the sent times of *lost* packets: if a packet is
not lost, we still have a SentPacket that keeps track of its own sent
time (this also reduces the amount of work in ack() for the most
common code path)
* reduce bounds on packets to track sent time of from 16384 to 128 (we
don't expect that many *lost* packets on short notice, and if we do,
not having a super-accurate RTT estimate is the least of our
problems)
* improve ack() CPU efficiency by using SentTimeCache instead of
SentTimes (we're no longer concerned about memory given the above, so
optimize for speed)
* use for(item : collection) wherever applicable for readability
* cleanup modified code to conform to the coding standards

SentTimeCache:
* this class replaces SentTimes
* uses a LinkedHashMap with O(1) lookup instead of a linear search
* uses more memory than SentTimes did, but we shouldn't care anymore

SentTimes:
* removed since it's highly inefficient by design and is no longer used

SentTimeCacheTest:
* new unit test for SentTimeCache