1
1
mirror of https://github.com/walles/moar.git synced 2024-09-11 20:17:13 +03:00

Lower memory usage by 10%

When loading a 577MB file.
This commit is contained in:
Johan Walles 2021-05-02 19:28:51 +02:00
parent 306442f2b2
commit 7a66c633ca
3 changed files with 8 additions and 8 deletions

View File

@ -24,27 +24,27 @@ var sgrSequencePattern = regexp.MustCompile("\x1b\\[([0-9;]*m)")
// A Line represents a line of text that can / will be paged
type Line struct {
raw *string
raw string
plain *string
}
// NewLine creates a new Line from a (potentially ANSI / man page formatted) string
func NewLine(raw string) *Line {
return &Line{
raw: &raw,
raw: raw,
plain: nil,
}
}
// Tokens returns a representation of the string split into styled tokens
func (line *Line) Tokens() []twin.Cell {
return cellsFromString(*line.raw)
return cellsFromString(line.raw)
}
// Plain returns a plain text representation of the initial string
func (line *Line) Plain() string {
if line.plain == nil {
plain := withoutFormatting(*line.raw)
plain := withoutFormatting(line.raw)
line.plain = &plain
}
return *line.plain

View File

@ -48,12 +48,12 @@ func TestTokenize(t *testing.T) {
var loglines strings.Builder
log.SetOutput(&loglines)
tokens := cellsFromString(*line.raw)
plainString := withoutFormatting(*line.raw)
tokens := cellsFromString(line.raw)
plainString := withoutFormatting(line.raw)
if len(tokens) != utf8.RuneCountInString(plainString) {
t.Errorf("%s:%d: len(tokens)=%d, len(plainString)=%d for: <%s>",
fileName, lineNumber,
len(tokens), utf8.RuneCountInString(plainString), *line.raw)
len(tokens), utf8.RuneCountInString(plainString), line.raw)
continue
}

View File

@ -23,7 +23,7 @@ func (p *Pager) Page() error {
_, height := p.screen.Size()
lines := p.reader.GetLines(p.firstLineOneBased, height-1).lines
for _, line := range lines {
fmt.Println(*line.raw)
fmt.Println(line.raw)
}
}()