mirror of
https://github.com/walles/moar.git
synced 2024-11-22 11:45:50 +03:00
Set fields before starting the reader thread
This is a better way to handle the startup race.
This commit is contained in:
parent
7809aafe5e
commit
8a8d9c3592
18
m/reader.go
18
m/reader.go
@ -48,7 +48,12 @@ type Reader struct {
|
||||
sync.Mutex
|
||||
|
||||
lines []*Line
|
||||
name *string
|
||||
|
||||
// Display name for the buffer. If not set, no buffer name will be shown.
|
||||
//
|
||||
// For files, this will be the file name. For our help text, this will be
|
||||
// "Help". For streams this will generally not be set.
|
||||
name *string
|
||||
|
||||
// If this is set, it will point out the file we are reading from. If this
|
||||
// is not set, we are not reading from a file.
|
||||
@ -93,10 +98,7 @@ type InputLines struct {
|
||||
//
|
||||
// go test -benchmem -benchtime=10s -run='^$' -bench 'ReadLargeFile'
|
||||
func (reader *Reader) preAllocLines() {
|
||||
reader.Lock()
|
||||
fileName := reader.fileName
|
||||
reader.Unlock()
|
||||
if fileName == nil {
|
||||
if reader.fileName == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -372,6 +374,7 @@ func newReaderFromStream(reader io.Reader, originalFileName *string, formatter c
|
||||
// lines while the pager is processing, the pager would miss
|
||||
// the lines added while it was processing.
|
||||
fileName: originalFileName,
|
||||
name: originalFileName,
|
||||
moreLinesAdded: make(chan bool, 1),
|
||||
maybeDone: make(chan bool, 1),
|
||||
highlightingStyle: make(chan chroma.Style, 1),
|
||||
@ -527,11 +530,6 @@ func NewReaderFromFilename(filename string, formatter chroma.Formatter, options
|
||||
|
||||
returnMe := newReaderFromStream(stream, &filename, formatter, options)
|
||||
|
||||
returnMe.Lock()
|
||||
returnMe.name = &filename
|
||||
returnMe.fileName = &filename
|
||||
returnMe.Unlock()
|
||||
|
||||
if options.Lexer == nil {
|
||||
returnMe.highlightingDone.Store(true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user