Skip to content

Commit

Permalink
Merge pull request #230 from noborus/improve-endnum
Browse files Browse the repository at this point in the history
Execute BuffEndNum() outside the loop
  • Loading branch information
noborus authored Dec 22, 2022
2 parents a62927d + 09a956a commit 28d168a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions oviewer/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ func (m *Document) firstLine() int {
return m.SkipLines + m.Header
}

// SearchLine searches the document and returns the matching line.
// SearchLine searches the document and returns the matching line number.
func (m *Document) SearchLine(ctx context.Context, searcher Searcher, lN int) (int, error) {
lN = max(lN, 0)

for n := lN; n < m.BufEndNum(); n++ {
end := m.BufEndNum()
for n := lN; n < end; n++ {
if searcher.Match(m.GetLine(n)) {
return n, nil
}
Expand All @@ -297,7 +297,7 @@ func (m *Document) SearchLine(ctx context.Context, searcher Searcher, lN int) (i
return 0, ErrNotFound
}

// BackSearchLine does a backward search on the document and returns a matching line.
// BackSearchLine does a backward search on the document and returns a matching line number.
func (m *Document) BackSearchLine(ctx context.Context, searcher Searcher, lN int) (int, error) {
lN = min(lN, m.BufEndNum()-1)

Expand Down

0 comments on commit 28d168a

Please sign in to comment.