Skip to content

Commit

Permalink
delete/refine: fix adjusting indices
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vrothberg committed Aug 23, 2022
1 parent e8db6b6 commit aca2836
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions vgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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:]...)
}

Expand Down

0 comments on commit aca2836

Please sign in to comment.