mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 16:07:42 +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:
@ -199,11 +199,12 @@ func (s *Session) run(ctx context.Context) {
|
|||||||
s.cancel(keys)
|
s.cancel(keys)
|
||||||
|
|
||||||
case <-s.tick.C:
|
case <-s.tick.C:
|
||||||
var live []*cid.Cid
|
live := make([]*cid.Cid, 0, len(s.liveWants))
|
||||||
|
now := time.Now()
|
||||||
for c := range s.liveWants {
|
for c := range s.liveWants {
|
||||||
cs, _ := cid.Cast([]byte(c))
|
cs, _ := cid.Cast([]byte(c))
|
||||||
live = append(live, cs)
|
live = append(live, cs)
|
||||||
s.liveWants[c] = time.Now()
|
s.liveWants[c] = now
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast these keys to everyone we're connected to
|
// Broadcast these keys to everyone we're connected to
|
||||||
|
Reference in New Issue
Block a user