Skip to content

Commit

Permalink
fix: Ensure that file input stream is size in runes
Browse files Browse the repository at this point in the history
Signed-off-by: Jim.Idle <jimi@idle.ws>
  • Loading branch information
jimidle authored and parrt committed Apr 18, 2023
1 parent 9cf07c1 commit 518121f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions runtime/Go/antlr/v4/file_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ func NewFileStream(fileName string) (*FileStream, error) {
fs := &FileStream{
InputStream: InputStream{
index: 0,
size: int(fInfo.Size()),
name: fileName,
},
filename: fileName,
}

// Pre-build the buffer and read runes efficiently
//
fs.data = make([]rune, 0, fs.size)
fs.data = make([]rune, 0, fInfo.Size())
for {
r, _, err := reader.ReadRune()
if err != nil {
break
}
fs.data = append(fs.data, r)
}
fs.size = len(fs.data) // Size in runes

// All done.
//
Expand Down

0 comments on commit 518121f

Please sign in to comment.