]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/syntax: remove unused field in (scanner) source
authorRobert Griesemer <gri@golang.org>
Wed, 5 Dec 2018 22:42:47 +0000 (14:42 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 5 Dec 2018 23:15:21 +0000 (23:15 +0000)
The source.offs field was intended for computing line offsets which
may allow a tiny optimization (see TODO in source.go). We haven't
done the optimization, so for now just remove the field to avoid
confusion. It's trivially added if needed.

While at it, also:

- Fix comment for ungetr2.
- Make sure sentinel is present even if reading from the io.Reader failed.

Change-Id: Ib056c6478030b3fe5fec29045362c8161ff3d19e
Reviewed-on: https://go-review.googlesource.com/c/152763
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/syntax/source.go

index 62eb0fdc30140988ca4333183b75c775cbd94f3d..c6168b8594f744571e6ef2a2dac9934f7f0b0c61 100644 (file)
@@ -33,7 +33,6 @@ type source struct {
 
        // source buffer
        buf         [4 << 10]byte
-       offs        int   // source offset of buf
        r0, r, w    int   // previous/current read and write buf positions, excluding sentinel
        line0, line uint  // previous/current line
        col0, col   uint  // previous/current column (byte offsets from line start)
@@ -51,7 +50,6 @@ func (s *source) init(src io.Reader, errh func(line, pos uint, msg string)) {
        s.errh = errh
 
        s.buf[0] = utf8.RuneSelf // terminate with sentinel
-       s.offs = 0
        s.r0, s.r, s.w = 0, 0, 0
        s.line0, s.line = 0, linebase
        s.col0, s.col = 0, colbase
@@ -68,7 +66,8 @@ func (s *source) ungetr() {
 
 // ungetr2 is like ungetr but enables a 2nd ungetr.
 // It must not be called if one of the runes seen
-// was a newline.
+// was a newline or had a UTF-8 encoding longer than
+// 1 byte.
 func (s *source) ungetr2() {
        s.ungetr()
        // line must not have changed
@@ -167,7 +166,6 @@ func (s *source) fill() {
                }
                n := s.r0 - 1
                copy(s.buf[:], s.buf[n:s.w])
-               s.offs += n
                s.r0 = 1 // eqv: s.r0 -= n
                s.r -= n
                s.w -= n
@@ -189,6 +187,7 @@ func (s *source) fill() {
                }
        }
 
+       s.buf[s.w] = utf8.RuneSelf // sentinel
        s.ioerr = io.ErrNoProgress
 }