modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)

* modernise: Run new gopls modernise tool against codebase

* Address shazbert's nits

* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling

* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS

* refactor: Various slice usage improvements and rename TODO

* tranches: Revert deleteByID changes due to performance decrease

Shazbert was a F1 driver in a past lifetime 🏎️

* tranches: Simply retrieve copy

Thanks to shazbert

* documentation: Sort contributors list by contributions

* tranches: Remove deadcode in deleteByID
This commit is contained in:
Adrian Gallagher
2025-03-21 09:17:10 +11:00
committed by GitHub
parent d857d704e3
commit 4651af5767
223 changed files with 1504 additions and 1752 deletions

View File

@@ -5,6 +5,7 @@ import (
"log"
"math/rand"
"os"
"slices"
"strconv"
"sync"
"testing"
@@ -570,35 +571,22 @@ func deploySliceOrdered() Tranches {
}
func TestReverse(t *testing.T) {
var b Base
b.VerifyOrderbook = true
if b.Bids = deploySliceOrdered(); len(b.Bids) != 1000 {
t.Fatal("incorrect length")
b := Base{
VerifyOrderbook: true,
}
err := b.Verify()
if !errors.Is(err, errPriceOutOfOrder) {
t.Fatalf("error expected %v received %v", errPriceOutOfOrder, err)
}
b.Bids = deploySliceOrdered()
require.Len(t, b.Bids, 1000)
assert.ErrorIs(t, b.Verify(), errPriceOutOfOrder)
b.Bids.Reverse()
err = b.Verify()
if err != nil {
t.Fatal(err)
}
assert.NoError(t, b.Verify())
b.Asks = append(b.Bids[:0:0], b.Bids...) //nolint:gocritic // Short hand
err = b.Verify()
if !errors.Is(err, errPriceOutOfOrder) {
t.Fatalf("error expected %v received %v", errPriceOutOfOrder, err)
}
b.Asks = slices.Clone(b.Bids)
assert.ErrorIs(t, b.Verify(), errPriceOutOfOrder)
b.Asks.Reverse()
err = b.Verify()
if err != nil {
t.Fatal(err)
}
assert.NoError(t, b.Verify())
}
// 705985 1856 ns/op 0 B/op 0 allocs/op

View File

@@ -84,18 +84,13 @@ updates:
continue
}
if y < len(*ts) {
copy((*ts)[y:], (*ts)[y+1:])
*ts = (*ts)[:len(*ts)-1]
} else {
*ts = append((*ts)[:y], (*ts)[y+1:]...)
}
copy((*ts)[y:], (*ts)[y+1:])
*ts = (*ts)[:len(*ts)-1]
continue updates
}
if !bypassErr {
return fmt.Errorf("delete error: %w %d not found",
errIDCannotBeMatched,
updts[x].ID)
return fmt.Errorf("delete error: %w %d not found", errIDCannotBeMatched, updts[x].ID)
}
}
return nil
@@ -117,7 +112,9 @@ func (ts Tranches) retrieve(count int) Tranches {
if count == 0 || count >= len(ts) {
count = len(ts)
}
return append(Tranches{}, ts[:count]...)
result := make(Tranches, count)
copy(result, ts)
return result
}
// updateInsertByPrice amends, inserts, moves and cleaves length of depth by

View File

@@ -1107,7 +1107,7 @@ func TestInsertUpdatesAsk(t *testing.T) {
}
// check checks depth values after an update has taken place
func Check(t *testing.T, depth interface{}, liquidity, value float64, expectedLen int) {
func Check(t *testing.T, depth any, liquidity, value float64, expectedLen int) {
t.Helper()
b, isBid := depth.(bidTranches)
a, isAsk := depth.(askTranches)