1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 15:42:21 +08:00

bitswap: fewer allocations in bitswap sessions

Also, don't call time.Now in a loop.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
Steven Allen
2017-12-05 10:10:18 -08:00
parent 15c734188f
commit 93151d4c33

View File

@ -199,11 +199,12 @@ func (s *Session) run(ctx context.Context) {
s.cancel(keys)
case <-s.tick.C:
var live []*cid.Cid
live := make([]*cid.Cid, 0, len(s.liveWants))
now := time.Now()
for c := range s.liveWants {
cs, _ := cid.Cast([]byte(c))
live = append(live, cs)
s.liveWants[c] = time.Now()
s.liveWants[c] = now
}
// Broadcast these keys to everyone we're connected to