]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Use unique.Handle for webseedUrlKey
authorMatt Joiner <anacrolix@gmail.com>
Mon, 4 Aug 2025 23:55:05 +0000 (09:55 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 4 Aug 2025 23:55:05 +0000 (09:55 +1000)
Should greatly improve apriori map lookup performance.

torrent.go
webseed-requesting.go

index edd86654d48eec1685a5c46e2e3eb59fa5e67dbf..31101f5908d797d11c0e338beafba6b97288180a 100644 (file)
@@ -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
 }
index a28244b71029795340d96dc6f63d80759da4903d..15de04384f1e0c2010a56bce1c599ef3adedf164 100644 (file)
@@ -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 {