From aca283642044ad21a8ba8d6831143e17b6662f89 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 23 Aug 2022 09:24:07 +0200 Subject: [PATCH] delete/refine: fix adjusting indices I have no recollection on why vgrep is even storing the indices in the cache. The cache is effectively a slice of slices such that indices are redundant and consume additional disk space and CPU cycles. Probably worth changing in a future release. Fixes: #183 Signed-off-by: Valentin Rothberg --- vgrep.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vgrep.go b/vgrep.go index 8b8dbaf..964e148 100644 --- a/vgrep.go +++ b/vgrep.go @@ -23,6 +23,7 @@ import ( "sync" "time" + "github.com/google/shlex" "github.com/jessevdk/go-flags" jsoniter "github.com/json-iterator/go" "github.com/mattn/go-shellwords" @@ -32,7 +33,6 @@ import ( "github.com/vrothberg/vgrep/internal/ansi" "github.com/vrothberg/vgrep/internal/colwriter" "golang.org/x/term" - "github.com/google/shlex" ) // Noticeably faster than the standard lib and battle tested. @@ -1002,10 +1002,10 @@ func (v *vgrep) commandDelete(indices []int) bool { for offset, idx := range indices { logrus.Debugf("deleting index %d", idx) - for i := idx + 1; i < len(v.matches); i++ { + index := idx - offset + for i := index; i < len(v.matches); i++ { v.matches[i][0] = strconv.Itoa(i - 1) } - index := idx - offset v.matches = append(v.matches[:index], v.matches[index+1:]...) }