]> Cypherpunks repositories - gostls13.git/commit
go/printer: don't emit unnecessary //line directives before empty lines
authorRobert Griesemer <gri@golang.org>
Fri, 2 Jun 2017 00:51:02 +0000 (17:51 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 2 Jun 2017 20:07:51 +0000 (20:07 +0000)
commita86362e07fb9e83f1ce15592764b4bb5751fe1e9
tree80afc24ff2f6c6f208121bd99a3398be84514f87
parent29469d2406d213187ee91bd256bb60e98e451324
go/printer: don't emit unnecessary //line directives before empty lines

1) Split atLineBegin into its two components: writing of // line directives
and writing of indentation (no functionality changes).

2) Don't call writeLineDirective at the beginning of a line if we're
writing white space - it's not necessary. This is the bug fix.

3) Move testing of the SourcePos mode out of writeLineDirective and
into the (single) caller. Clearer and more efficient.

(Instead of these 3 changes one could also have simply called the
original atLineBegin with position p.out rather than p.pos. This
would have caused atLineBegin to not write a line directive.
Factoring the code seemed like a cleaner and more direct approach.)

Fixes #5945.

Change-Id: Ia8710806b6d3d4e5044116b142c036a4ab5a1764
Reviewed-on: https://go-review.googlesource.com/44651
Reviewed-by: Alan Donovan <adonovan@google.com>
src/go/printer/printer.go
src/go/printer/printer_test.go