From: Matt Joiner Date: Fri, 10 Sep 2021 13:02:20 +0000 (+1000) Subject: Optimize requesting peerId Uintptr allocation X-Git-Tag: v1.32.0~78 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c4445fd201f60361e7ed8f31cf5302143b64c8a2;p=btrtrc.git Optimize requesting peerId Uintptr allocation --- 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() }