From 67966466ecb288a08b23033e614919e5f3d895f1 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 5 Aug 2025 09:55:05 +1000 Subject: [PATCH] Use unique.Handle for webseedUrlKey Should greatly improve apriori map lookup performance. --- torrent.go | 6 +++--- webseed-requesting.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/torrent.go b/torrent.go index edd86654..31101f59 100644 --- a/torrent.go +++ b/torrent.go @@ -1005,7 +1005,7 @@ func (t *Torrent) newMetaInfo() metainfo.MetaInfo { UrlList: func() []string { ret := make([]string, 0, len(t.webSeeds)) for url := range t.webSeeds { - ret = append(ret, string(url)) + ret = append(ret, unique.Handle[string](url).Value()) } return ret }(), @@ -3030,7 +3030,7 @@ func (t *Torrent) addWebSeed(url string, opts ...AddWebSeedsOpt) bool { if t.cl.config.DisableWebseeds { return false } - if _, ok := t.webSeeds[webseedUrlKey(url)]; ok { + if _, ok := t.webSeeds[webseedUrlKey(unique.Make(url))]; ok { return false } // I don't think Go http supports pipelining requests. However, we can have more ready to go @@ -3084,7 +3084,7 @@ func (t *Torrent) addWebSeed(url string, opts ...AddWebSeedsOpt) bool { if t.haveInfo() { ws.onGotInfo(t.info) } - t.webSeeds[webseedUrlKey(url)] = &ws + t.webSeeds[webseedUrlKey(unique.Make(url))] = &ws ws.peer.onNeedUpdateRequests("Torrent.addWebSeed") return true } diff --git a/webseed-requesting.go b/webseed-requesting.go index a28244b7..15de0438 100644 --- a/webseed-requesting.go +++ b/webseed-requesting.go @@ -35,7 +35,7 @@ func init() { type ( webseedHostKey string webseedHostKeyHandle = unique.Handle[webseedHostKey] - webseedUrlKey string + webseedUrlKey unique.Handle[string] ) /* @@ -263,9 +263,9 @@ func (me webseedRequestPlan) String() string { // Distinct webseed request data when different offsets are not allowed. type aprioriWebseedRequestKey struct { + url webseedUrlKey t *Torrent sliceIndex RequestIndex - url webseedUrlKey } func (me *aprioriWebseedRequestKey) String() string { -- 2.51.0