Quellcode durchsuchen

internal/encoding/text: minor tweak in inserting random whitespace

Simply move logic into similar code block.  Maintains the same logic.

Change-Id: I7b5a3f3d57f6102c7919cdc03dd105f08d21aca3
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/194039
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Herbie Ong vor 6 Jahren
Ursprung
Commit
4eb4d61b0c
1 geänderte Dateien mit 10 neuen und 10 gelöschten Zeilen
  1. 10 10
      internal/encoding/text/encode.go

+ 10 - 10
internal/encoding/text/encode.go

@@ -113,11 +113,11 @@ func (p *encoder) marshalMessage(v Value, emitDelims bool) error {
 		p.out = append(p.out, ':')
 		if len(p.indent) > 0 {
 			p.out = append(p.out, ' ')
-		}
-		// For multi-line output, add a random extra space after key: per message to
-		// make output unstable.
-		if len(p.indent) > 0 && detrand.Bool() {
-			p.out = append(p.out, ' ')
+			// For multi-line output, add a random extra space after key:
+			// to make output unstable.
+			if detrand.Bool() {
+				p.out = append(p.out, ' ')
+			}
 		}
 
 		if err := p.marshalValue(item[1]); err != nil {
@@ -125,11 +125,11 @@ func (p *encoder) marshalMessage(v Value, emitDelims bool) error {
 		}
 		if i < len(items)-1 && len(p.indent) == 0 {
 			p.out = append(p.out, ' ')
-		}
-		// For single-line output, add a random extra space after a field per message to
-		// make output unstable.
-		if len(p.indent) == 0 && detrand.Bool() && i != len(items)-1 {
-			p.out = append(p.out, ' ')
+			// For single-line output, add a random extra space after a field
+			// to make output unstable.
+			if detrand.Bool() {
+				p.out = append(p.out, ' ')
+			}
 		}
 		p.out = append(p.out, p.newline...)
 	}