1
1
mirror of https://github.com/walles/moar.git synced 2024-09-11 12:15:43 +03:00

Fix the line counts

This commit is contained in:
Johan Walles 2024-05-18 07:44:01 +02:00
parent 387fb348c7
commit 625193933d

View File

@ -43,7 +43,22 @@ func (p *Pager) findFirstHit(startPosition linenumbers.LineNumber, beforePositio
// If the number of lines to search matches the number of cores (or more),
// divide the search into chunks. Otherwise use one chunk.
chunkCount := runtime.NumCPU()
linesCount := p.reader.GetLineCount() - startPosition.AsZeroBased()
var linesCount int
if backwards {
// If the startPosition is zero, that should make the count one
linesCount = startPosition.AsZeroBased() + 1
if beforePosition != nil {
// Searching from 1 with before set to 0 should make the count 1
linesCount = startPosition.AsZeroBased() - beforePosition.AsZeroBased()
}
} else {
linesCount = p.reader.GetLineCount() - startPosition.AsZeroBased()
if beforePosition != nil {
// Searching from 1 with before set to 2 should make the count 1
linesCount = beforePosition.AsZeroBased() - startPosition.AsZeroBased()
}
}
if linesCount < chunkCount {
chunkCount = 0
}