diff --git a/pipeline/forkhandler.go b/pipeline/forkhandler.go index b302ecce8..65d7dc240 100644 --- a/pipeline/forkhandler.go +++ b/pipeline/forkhandler.go @@ -1,6 +1,7 @@ package pipeline import ( + "slices" "sync" pbssinternal "github.com/streamingfast/substreams/pb/sf/substreams/intern/v2" @@ -42,8 +43,8 @@ func (f *ForkHandler) joinReversibleOutputs(target *pbsubstreams.Clock, previous defer f.mu.Unlock() reversibleOutputs := f.reversibleOutputs[target.Id] - for i := len(previousClocks) - 1; i >= 0; i-- { - if clock := previousClocks[i]; clock != nil { + for _, v := range slices.Backward(previousClocks) { + if clock := v; clock != nil { if outputs, found := f.reversibleOutputs[clock.Id]; found { reversibleOutputs = append(reversibleOutputs, outputs...) delete(f.reversibleOutputs, clock.Id) diff --git a/pipeline/process_block.go b/pipeline/process_block.go index 3ae782dd2..6bcaf3cde 100644 --- a/pipeline/process_block.go +++ b/pipeline/process_block.go @@ -7,6 +7,7 @@ import ( "io" "os" "runtime/debug" + "slices" "strconv" "connectrpc.com/connect" @@ -234,8 +235,7 @@ func (p *Pipeline) undoPartialStates() error { return nil } - for i := len(p.partialProcessingState.processedPartials) - 1; i >= 0; i-- { - clk := p.partialProcessingState.processedPartials[i] + for _, clk := range slices.Backward(p.partialProcessingState.processedPartials) { if err := p.forkHandler.handleUndo(clk); err != nil { return fmt.Errorf("reverting outputs: %w", err) } diff --git a/storage/store/delta.go b/storage/store/delta.go index acdcbbaed..1c8e2172e 100644 --- a/storage/store/delta.go +++ b/storage/store/delta.go @@ -3,6 +3,7 @@ package store import ( "errors" "fmt" + "slices" "strings" pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1" @@ -92,8 +93,7 @@ func storeTooBigError(storeName string, size, limit uint64) error { func (b *baseStore) ApplyDeltasReverse(deltas []*pbsubstreams.StoreDelta) { b.recentlyDeletedPrefixes.Clear() // whenever we have an undo block, we clear this cache to avoid any bug - for i := len(deltas) - 1; i >= 0; i-- { - delta := deltas[i] + for _, delta := range slices.Backward(deltas) { newSize := uint64(len(delta.NewValue)) oldSize := uint64(len(delta.OldValue)) diff --git a/storage/store/value_get.go b/storage/store/value_get.go index 72ce997b1..d003ad812 100644 --- a/storage/store/value_get.go +++ b/storage/store/value_get.go @@ -3,6 +3,7 @@ package store import ( "bytes" "fmt" + "slices" pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1" ) @@ -63,8 +64,7 @@ func (b *baseStore) HasFirst(key string) bool { } func (b *baseStore) getLast(key string) ([]byte, bool) { - for i := len(b.deltas) - 1; i >= 0; i-- { - delta := b.deltas[i] + for _, delta := range slices.Backward(b.deltas) { if delta.Key != key { continue } @@ -96,8 +96,7 @@ func (b *baseStore) GetLast(key string) ([]byte, bool) { } func (b *baseStore) HasLast(key string) bool { - for i := len(b.deltas) - 1; i >= 0; i-- { - delta := b.deltas[i] + for _, delta := range slices.Backward(b.deltas) { if delta.Key != key { continue } @@ -119,8 +118,7 @@ func (b *baseStore) HasLast(key string) bool { func (b *baseStore) getAt(ord uint64, key string) (out []byte, found bool) { out, found = b.getLast(key) - for i := len(b.deltas) - 1; i >= 0; i-- { - delta := b.deltas[i] + for _, delta := range slices.Backward(b.deltas) { if delta.Ordinal <= ord { break } @@ -161,8 +159,7 @@ func (b *baseStore) GetAt(ord uint64, key string) (out []byte, found bool) { func (b *baseStore) HasAt(ord uint64, key string) bool { _, found := b.GetFirst(key) - for i := len(b.deltas) - 1; i >= 0; i-- { - delta := b.deltas[i] + for _, delta := range slices.Backward(b.deltas) { if delta.Ordinal <= ord { break } diff --git a/tui2/pages/output/output.go b/tui2/pages/output/output.go index b3a035691..395df5517 100644 --- a/tui2/pages/output/output.go +++ b/tui2/pages/output/output.go @@ -305,8 +305,7 @@ func (o *Output) Update(msg tea.Msg) (tea.Model, tea.Cmd) { o.statusBar.SetBytesRepresentation(o.bytesRepresentation) o.setOutputViewContent(true) case "N": - for i := len(o.searchMatchingOutputViewOffsets) - 1; i >= 0; i-- { - pos := o.searchMatchingOutputViewOffsets[i] + for _, pos := range slices.Backward(o.searchMatchingOutputViewOffsets) { if pos < o.outputView.YOffset { o.outputView.YOffset = pos break @@ -554,8 +553,7 @@ func (o *Output) jumpToPreviousMatchingBlock() tea.Cmd { activeBlock := o.active.BlockNum blocks := o.searchBlockNumsWithMatches return func() tea.Msg { - for i := len(blocks) - 1; i >= 0; i-- { - block := blocks[i] + for _, block := range slices.Backward(blocks) { if block < activeBlock { return blockselect.BlockChangedMsg(block) }