11package input
22
33import (
4- "container/list"
54 "fmt"
65
76 "github.com/johnkerl/miller/v6/pkg/bifs"
@@ -28,7 +27,7 @@ func NewPseudoReaderGen(
2827func (reader * PseudoReaderGen ) Read (
2928 filenames []string , // ignored
3029 context types.Context ,
31- readerChannel chan <- * list. List , // list of *types.RecordAndContext
30+ readerChannel chan <- [] * types. RecordAndContext , // list of *types.RecordAndContext
3231 errorChannel chan error ,
3332 downstreamDoneChannel <- chan bool , // for mlr head
3433) {
@@ -38,7 +37,7 @@ func (reader *PseudoReaderGen) Read(
3837
3938func (reader * PseudoReaderGen ) process (
4039 context * types.Context ,
41- readerChannel chan <- * list. List , // list of *types.RecordAndContext
40+ readerChannel chan <- [] * types. RecordAndContext , // list of *types.RecordAndContext
4241 errorChannel chan error ,
4342 downstreamDoneChannel <- chan bool , // for mlr head
4443) {
@@ -71,7 +70,7 @@ func (reader *PseudoReaderGen) process(
7170 key := reader .readerOptions .GeneratorOptions .FieldName
7271 value := start .Copy ()
7372
74- recordsAndContexts := list . New ( )
73+ recordsAndContexts := make ([] * types. RecordAndContext , 0 , recordsPerBatch )
7574
7675 eof := false
7776 for ! eof {
@@ -84,11 +83,11 @@ func (reader *PseudoReaderGen) process(
8483 record .PutCopy (key , value )
8584
8685 context .UpdateForInputRecord ()
87- recordsAndContexts . PushBack ( types .NewRecordAndContext (record , context ))
86+ recordsAndContexts = append ( recordsAndContexts , types .NewRecordAndContext (record , context ))
8887
89- if int64 (recordsAndContexts . Len ( )) >= recordsPerBatch {
88+ if int64 (len ( recordsAndContexts )) >= recordsPerBatch {
9089 readerChannel <- recordsAndContexts
91- recordsAndContexts = list . New ( )
90+ recordsAndContexts = make ([] * types. RecordAndContext , 0 , recordsPerBatch )
9291
9392 // See if downstream processors will be ignoring further data (e.g.
9493 // mlr head). If so, stop reading. This makes 'mlr head hugefile'
@@ -111,7 +110,7 @@ func (reader *PseudoReaderGen) process(
111110 value = bifs .BIF_plus_binary (value , step )
112111 }
113112
114- if recordsAndContexts . Len ( ) > 0 {
113+ if len ( recordsAndContexts ) > 0 {
115114 readerChannel <- recordsAndContexts
116115 }
117116}
0 commit comments