bencode/bench_test.go | 4 +--- client_test.go | 9 ++++----- cmd/torrent-metainfo-pprint/main.go | 3 +-- cmd/torrent-verify/main.go | 3 +-- iplist/iplist_test.go | 3 +-- misc_test.go | 2 +- mse/mse_test.go | 11 +++++------ peer_protocol/decoder_test.go | 3 +-- peerconn.go | 6 +++--- peerconn_test.go | 3 +-- request-strategy/order_test.go | 3 +-- rlreader_test.go | 5 ++--- storage/test/bench-piece-mark-complete.go | 8 ++++---- torrent.go | 3 +-- torrent_test.go | 5 ++--- diff --git a/bencode/bench_test.go b/bencode/bench_test.go index f5fb0a7a79f1a976d4ee007d154de4f5178e65e9..d6faafb76a124989f40abd52b26ecf1b453118d4 100644 --- a/bencode/bench_test.go +++ b/bencode/bench_test.go @@ -6,8 +6,6 @@ "reflect" "testing" "github.com/anacrolix/dht/v2/krpc" - "github.com/bradfitz/iter" - "github.com/anacrolix/torrent/bencode" ) @@ -40,7 +38,7 @@ tb.Fail() } tb.ReportAllocs() tb.ResetTimer() - for range iter.N(tb.N) { + for i := 0; i < tb.N; i += 1 { marshalAndUnmarshal(tb, orig) } } diff --git a/client_test.go b/client_test.go index c626ff890ddedaf0b8346a2abc604c84351cb06d..f170c9e3f60f70ef891c07ab6c04a69a32a1acda 100644 --- a/client_test.go +++ b/client_test.go @@ -12,7 +12,6 @@ "testing" "testing/iotest" "time" - "github.com/bradfitz/iter" "github.com/frankban/quicktest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -131,7 +130,7 @@ func TestAddDropManyTorrents(t *testing.T) { cl, err := NewClient(TestingConfig(t)) require.NoError(t, err) defer cl.Close() - for i := range iter.N(1000) { + for i := 0; i < 1000; i += 1 { var spec TorrentSpec binary.PutVarint(spec.InfoHash[:], int64(i)) tt, new, err := cl.AddTorrentSpec(&spec) @@ -203,7 +202,7 @@ cl, err := NewClient(cfg) require.NoError(b, err) defer cl.Close() b.ReportAllocs() - for range iter.N(b.N) { + for i := 0; i < b.N; i += 1 { t, err := cl.AddTorrentFromFile("testdata/bootstrap.dat.torrent") if err != nil { b.Fatal(err) @@ -354,7 +353,7 @@ } } func writeTorrentData(ts *storage.Torrent, info metainfo.Info, b []byte) { - for i := range iter.N(info.NumPieces()) { + for i := 0; i < info.NumPieces(); i += 1 { p := info.Piece(i) ts.Piece(p).WriteAt(b[p.Offset():p.Offset()+p.Length()], 0) } @@ -609,7 +608,7 @@ ih := testutil.GreetingMetaInfo().HashInfoBytes() cfg := TestingConfig(t) cfg.DisableAcceptRateLimiting = true cfg.DropDuplicatePeerIds = true - for i := range iter.N(3) { + for i := 0; i < 3; i += 1 { cl, err := NewClient(cfg) require.NoError(t, err) defer cl.Close() diff --git a/cmd/torrent-metainfo-pprint/main.go b/cmd/torrent-metainfo-pprint/main.go index 16f2b3039fe37df28f41b208bba57dfafd914697..cfecc22416a2758fe42e0016b49d318fd9ae1790 100644 --- a/cmd/torrent-metainfo-pprint/main.go +++ b/cmd/torrent-metainfo-pprint/main.go @@ -11,7 +11,6 @@ "os" "github.com/anacrolix/envpprof" "github.com/anacrolix/tagflag" - "github.com/bradfitz/iter" "github.com/anacrolix/torrent/metainfo" ) @@ -55,7 +54,7 @@ d["Files"] = info.UpvertedFiles() } if flags.PieceHashes { d["PieceHashes"] = func() (ret []string) { - for i := range iter.N(info.NumPieces()) { + for i, numPieces := 0, info.NumPieces(); i < numPieces; i += 1 { ret = append(ret, hex.EncodeToString(info.Pieces[i*20:(i+1)*20])) } return diff --git a/cmd/torrent-verify/main.go b/cmd/torrent-verify/main.go index 0b7f21543bcd3c4bef5bcf2764c6329b10b0d417..47c7f3a36096c981572388d2a83f522e6358871b 100644 --- a/cmd/torrent-verify/main.go +++ b/cmd/torrent-verify/main.go @@ -10,7 +10,6 @@ "os" "path/filepath" "github.com/anacrolix/tagflag" - "github.com/bradfitz/iter" "github.com/edsrzf/mmap-go" "github.com/anacrolix/torrent/metainfo" @@ -47,7 +46,7 @@ } span.Append(mm) } span.InitIndex() - for i := range iter.N(info.NumPieces()) { + for i, numPieces := 0, info.NumPieces(); i < numPieces; i += 1 { p := info.Piece(i) hash := sha1.New() _, err := io.Copy(hash, io.NewSectionReader(span, p.Offset(), p.Length())) diff --git a/iplist/iplist_test.go b/iplist/iplist_test.go index 8062f09b10c63ec8d3cdfd3a4758d76547bc96c3..4e36e0aef14739fa5c710782ced01bb1c7822e82 100644 --- a/iplist/iplist_test.go +++ b/iplist/iplist_test.go @@ -7,7 +7,6 @@ "net" "strings" "testing" - "github.com/bradfitz/iter" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -41,7 +40,7 @@ } func TestIPv4RangeLen(t *testing.T) { ranges, _ := sampleRanges(t) - for i := range iter.N(3) { + for i := 0; i < 3; i += 1 { if len(ranges[i].First) != 4 { t.FailNow() } diff --git a/misc_test.go b/misc_test.go index 5190e4f49fffa73fca18bfeb113034e42bf3409d..d8c0c7aab2850b0abc14c49e2f00102ac1397d16 100644 --- a/misc_test.go +++ b/misc_test.go @@ -25,7 +25,7 @@ } func BenchmarkIterBitmapsDistinct(t *testing.B) { t.ReportAllocs() - for range iter.N(t.N) { + for i := 0; i < t.N; i += 1 { var skip, first, second bitmap.Bitmap skip.Add(1) first.Add(1, 0, 3) diff --git a/mse/mse_test.go b/mse/mse_test.go index f13c259f6c19f9c4bb400ae0ed0951fb86305a62..33fd9c5edb23d61a749b775426e5307b3c51f032 100644 --- a/mse/mse_test.go +++ b/mse/mse_test.go @@ -11,7 +11,6 @@ "sync" "testing" _ "github.com/anacrolix/envpprof" - "github.com/bradfitz/iter" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -114,7 +113,7 @@ allHandshakeTests(t, AllSupportedCrypto, func(CryptoMethod) CryptoMethod { return CryptoMethodPlaintext }) } func BenchmarkHandshakeDefault(b *testing.B) { - for range iter.N(b.N) { + for i := 0; i < b.N; i += 1 { allHandshakeTests(b, AllSupportedCrypto, DefaultCryptoSelector) } } @@ -171,7 +170,7 @@ fillRand(t, ia, a, b) t.StopTimer() t.SetBytes(int64(len(ia) + len(a) + len(b))) t.ResetTimer() - for range iter.N(t.N) { + for i := 0; i < t.N; i += 1 { ac, bc := net.Pipe() ar := make([]byte, len(b)) br := make([]byte, len(ia)+len(a)) @@ -239,7 +238,7 @@ require.Equal(t, len(a), n) b := make([]byte, len(a)) t.SetBytes(int64(len(a))) t.ResetTimer() - for range iter.N(t.N) { + for i := 0; i < t.N; i += 1 { n, _ = w.Write(a) if n != len(a) { t.FailNow() @@ -256,7 +255,7 @@ } func BenchmarkSkeysReceive(b *testing.B) { var skeys [][]byte - for range iter.N(100000) { + for i := 0; i < 100000; i += 1 { skeys = append(skeys, make([]byte, 20)) } fillRand(b, skeys...) @@ -264,7 +263,7 @@ initSkey := skeys[len(skeys)/2] //c := qt.New(b) b.ReportAllocs() b.ResetTimer() - for range iter.N(b.N) { + for i := 0; i < b.N; i += 1 { initiator, receiver := net.Pipe() go func() { _, _, err := InitiateHandshake(initiator, initSkey, nil, AllSupportedCrypto) diff --git a/peer_protocol/decoder_test.go b/peer_protocol/decoder_test.go index 33909cdc321d96f0e6e978891223566d780627c6..2f94e0ee1b81a7afeda41c0eaf2aa05c3e74ce4e 100644 --- a/peer_protocol/decoder_test.go +++ b/peer_protocol/decoder_test.go @@ -6,7 +6,6 @@ "io" "sync" "testing" - "github.com/bradfitz/iter" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -46,7 +45,7 @@ return &b }, }, } - for range iter.N(t.N) { + for i := 0; i < t.N; i += 1 { var msg Message require.NoError(t, d.Decode(&msg)) // WWJD diff --git a/peerconn.go b/peerconn.go index fda3b95fcdb093b2b105e41776a35d13355288a7..4aee30fdbf557f712f5e2fa08c3d51a46a4e92b8 100644 --- a/peerconn.go +++ b/peerconn.go @@ -784,9 +784,9 @@ func (cn *Peer) onPeerHasAllPieces() { t := cn.t if t.haveInfo() { - pp := cn.newPeerPieces() - for i := range iter.N(t.numPieces()) { - if !pp.Contains(bitmap.BitIndex(i)) { + npp, pc := cn.newPeerPieces(), t.numPieces() + for i := 0; i < pc; i += 1 { + if !npp.Contains(bitmap.BitIndex(i)) { t.incPieceAvailability(i) } } diff --git a/peerconn_test.go b/peerconn_test.go index c28bc6328bb0244d8a17846ae5bac1c782bdcd51..8ad5c737e177ad985286ce6df048d63772f8321c 100644 --- a/peerconn_test.go +++ b/peerconn_test.go @@ -7,7 +7,6 @@ "sync" "testing" "github.com/anacrolix/missinggo/pubsub" - "github.com/bradfitz/iter" "github.com/frankban/quicktest" "github.com/stretchr/testify/require" @@ -128,7 +127,7 @@ b.SetBytes(int64(len(msg.Piece))) go func() { defer w.Close() ts.writeSem.Lock() - for range iter.N(b.N) { + for i := 0; i < b.N; i += 1 { cl.lock() // The chunk must be written to storage everytime, to ensure the // writeSem is unlocked. diff --git a/request-strategy/order_test.go b/request-strategy/order_test.go index d37b0423ec0b5192dd93f447d1c5b3783102759b..89a85085bff67f053ec0fff6c63ba48c0c091145 100644 --- a/request-strategy/order_test.go +++ b/request-strategy/order_test.go @@ -4,7 +4,6 @@ import ( "math" "testing" - "github.com/bradfitz/iter" qt "github.com/frankban/quicktest" pp "github.com/anacrolix/torrent/peer_protocol" @@ -16,7 +15,7 @@ } func chunkIterRange(end int) func(func(ChunkSpec)) { return func(f func(ChunkSpec)) { - for offset := range iter.N(end) { + for offset := 0; offset < end; offset += 1 { f(ChunkSpec{pp.Integer(offset), 1}) } } diff --git a/rlreader_test.go b/rlreader_test.go index 0391c619b1c4e08247df9752468cbc0afd6f7154..6bf25c432c6ba3269c9cbbce2ecf81d2681dc323 100644 --- a/rlreader_test.go +++ b/rlreader_test.go @@ -8,7 +8,6 @@ "sync" "testing" "time" - "github.com/bradfitz/iter" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/time/rate" @@ -59,7 +58,7 @@ At time.Time } reads := make(chan read) done := make(chan struct{}) - for range iter.N(numReaders) { + for i := 0; i < numReaders; i += 1 { r, w := io.Pipe() ws = append(ws, w) cs = append(cs, w) @@ -99,7 +98,7 @@ wg.Wait() }() written := 0 go func() { - for range iter.N(writeRounds) { + for i := 0; i < writeRounds; i += 1 { err := writeN(ws, bytesPerRound) if err != nil { log.Printf("error writing: %s", err) diff --git a/storage/test/bench-piece-mark-complete.go b/storage/test/bench-piece-mark-complete.go index 6e04702bc2c448d07b1f8384094b3fb691b513c9..e800e6a90b3eb83897eff56296e7b06bb23756c3 100644 --- a/storage/test/bench-piece-mark-complete.go +++ b/storage/test/bench-piece-mark-complete.go @@ -8,7 +8,6 @@ "testing" "github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/storage" - "github.com/bradfitz/iter" qt "github.com/frankban/quicktest" ) @@ -41,7 +40,7 @@ data := make([]byte, pieceSize) readData := make([]byte, pieceSize) b.SetBytes(int64(numPieces) * pieceSize) oneIter := func() { - for pieceIndex := range iter.N(numPieces) { + for pieceIndex := 0; pieceIndex < numPieces; pieceIndex += 1 { pi := tw.Piece(info.Piece(pieceIndex)) rand.Read(data) b.StartTimer() @@ -76,12 +75,13 @@ } } // Fill the cache if capacity > 0 { - for range iter.N(int((capacity + info.TotalLength() - 1) / info.TotalLength())) { + iterN := int((capacity + info.TotalLength() - 1) / info.TotalLength()) + for i := 0; i < iterN; i += 1 { oneIter() } } b.ResetTimer() - for range iter.N(b.N) { + for i := 0; i < b.N; i += 1 { oneIter() } } diff --git a/torrent.go b/torrent.go index 0481d5649808c68639dea2dc6877f787de204d35..6f4730e2eaa606a414f53e7a9ee815d9a564f333 100644 --- a/torrent.go +++ b/torrent.go @@ -21,7 +21,6 @@ "github.com/RoaringBitmap/roaring" "github.com/anacrolix/chansync" "github.com/anacrolix/dht/v2" "github.com/anacrolix/log" - "github.com/anacrolix/missinggo/iter" "github.com/anacrolix/missinggo/perf" "github.com/anacrolix/missinggo/pubsub" "github.com/anacrolix/missinggo/slices" @@ -2237,7 +2236,7 @@ }, activeRequests: make(map[Request]webseed.Request, maxRequests), } ws.requesterCond.L = t.cl.locker() - for range iter.N(maxRequests) { + for i := 0; i < maxRequests; i += 1 { go ws.requester() } for _, f := range t.callbacks().NewPeer { diff --git a/torrent_test.go b/torrent_test.go index 053ed5d1a444b8b8d9c9461e865ed5ca03343b73..bd762c9c009bc04c38b752b381fb9178540428c0 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -10,7 +10,6 @@ "testing" "github.com/anacrolix/missinggo/v2" "github.com/anacrolix/missinggo/v2/bitmap" - "github.com/bradfitz/iter" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -91,7 +90,7 @@ PieceLength: pieceLength, Length: pieceLength * numPieces, })) assert.EqualValues(b, 13410, t.numPieces()) - for range iter.N(7) { + for i := 0; i < 7; i += 1 { r := t.NewReader() r.SetReadahead(32 << 20) r.Seek(3500000, io.SeekStart) @@ -101,7 +100,7 @@ for i := 0; i < t.numPieces(); i += 3 { t._completedPieces.Add(bitmap.BitIndex(i)) } t.DownloadPieces(0, t.numPieces()) - for range iter.N(b.N) { + for i := 0; i < b.N; i += 1 { t.updateAllPiecePriorities() } }