From 505551d27de2aac355ddfb82adc54fc2c5ed4dc5 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 20 Apr 2024 09:32:52 +1000 Subject: [PATCH] Remove unused pendingRequests Includes a large global allocation that we don't need. https://github.com/anacrolix/torrent/issues/930#issuecomment-2066055987 --- pending-requests.go | 50 ---------------------------------------- pending-requests_test.go | 12 ---------- 2 files changed, 62 deletions(-) delete mode 100644 pending-requests.go delete mode 100644 pending-requests_test.go diff --git a/pending-requests.go b/pending-requests.go deleted file mode 100644 index dcb1faf1..00000000 --- a/pending-requests.go +++ /dev/null @@ -1,50 +0,0 @@ -package torrent - -import ( - rbm "github.com/RoaringBitmap/roaring" - roaring "github.com/RoaringBitmap/roaring/BitSliceIndexing" -) - -type pendingRequests struct { - m *roaring.BSI -} - -func (p *pendingRequests) Dec(r RequestIndex) { - _r := uint64(r) - prev, _ := p.m.GetValue(_r) - if prev <= 0 { - panic(prev) - } - p.m.SetValue(_r, prev-1) -} - -func (p *pendingRequests) Inc(r RequestIndex) { - _r := uint64(r) - prev, _ := p.m.GetValue(_r) - p.m.SetValue(_r, prev+1) -} - -func (p *pendingRequests) Init(maxIndex RequestIndex) { - p.m = roaring.NewDefaultBSI() -} - -var allBits rbm.Bitmap - -func init() { - allBits.AddRange(0, rbm.MaxRange) -} - -func (p *pendingRequests) AssertEmpty() { - if p.m == nil { - panic(p.m) - } - sum, _ := p.m.Sum(&allBits) - if sum != 0 { - panic(sum) - } -} - -func (p *pendingRequests) Get(r RequestIndex) int { - count, _ := p.m.GetValue(uint64(r)) - return int(count) -} diff --git a/pending-requests_test.go b/pending-requests_test.go deleted file mode 100644 index 6c9572e0..00000000 --- a/pending-requests_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package torrent - -// // Ensure that cmp.Diff will detect errors as required. -// func TestPendingRequestsDiff(t *testing.T) { -// var a, b pendingRequests -// c := qt.New(t) -// diff := func() string { return cmp.Diff(a.m, b.m) } -// c.Check(diff(), qt.ContentEquals, "") -// a.m = []int{1, 3} -// b.m = []int{1, 2, 3} -// c.Check(diff(), qt.Not(qt.Equals), "") -// } -- 2.48.1