From c4445fd201f60361e7ed8f31cf5302143b64c8a2 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 10 Sep 2021 23:02:20 +1000 Subject: [PATCH] Optimize requesting peerId Uintptr allocation --- requesting.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/requesting.go b/requesting.go index 15033bb0..16da8393 100644 --- a/requesting.go +++ b/requesting.go @@ -84,7 +84,10 @@ func (cl *Client) doRequests() { }, DownloadRate: p.downloadRate(), Age: time.Since(p.completedHandshake), - Id: (*peerId)(p), + Id: peerId{ + Peer: p, + ptr: uintptr(unsafe.Pointer(p)), + }, }) }) ts = append(ts, rst) @@ -98,14 +101,17 @@ func (cl *Client) doRequests() { } } -type peerId Peer +type peerId struct { + *Peer + ptr uintptr +} -func (p *peerId) Uintptr() uintptr { - return uintptr(unsafe.Pointer(p)) +func (p peerId) Uintptr() uintptr { + return p.ptr } func setPeerNextRequestState(_p request_strategy.PeerId, rp request_strategy.PeerNextRequestState) { - p := (*Peer)(_p.(*peerId)) + p := _p.(peerId).Peer p.nextRequestState = rp p.onNextRequestStateChanged() } -- 2.48.1