diff options
author | Nia Waldvogel <[email protected]> | 2021-12-30 10:17:35 -0500 |
---|---|---|
committer | Nia <[email protected]> | 2021-12-30 12:03:12 -0500 |
commit | f9f2349850cd8a7777045dff249f49ede12e3e07 (patch) | |
tree | 8ff153b184f25263fa5c9da25a0fdfc173fef5b1 /main.go | |
parent | f1b15db258038d098f3a8ac57afe6266acb48253 (diff) | |
download | tinygo-f9f2349850cd8a7777045dff249f49ede12e3e07.tar.gz tinygo-f9f2349850cd8a7777045dff249f49ede12e3e07.zip |
tinygo test: simplify output buffering
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 32 |
1 files changed, 14 insertions, 18 deletions
@@ -1641,15 +1641,13 @@ func (out *testStdout) Write(data []byte) (int, error) { defer buf.mu.Unlock() // Append the output. - var prev []byte - if len(buf.output) > 0 && !buf.output[len(buf.output)-1].stderr { - prev = buf.output[len(buf.output)-1].data - buf.output = buf.output[:len(buf.output)-1] - } - buf.output = append(buf.output, outputEntry{ - stderr: false, - data: append(prev, data...), - }) + if len(buf.output) == 0 || buf.output[len(buf.output)-1].stderr { + buf.output = append(buf.output, outputEntry{ + stderr: false, + }) + } + last := &buf.output[len(buf.output)-1] + last.data = append(last.data, data...) return len(data), nil } @@ -1674,15 +1672,13 @@ func (out *testStderr) Write(data []byte) (int, error) { defer buf.mu.Unlock() // Append the output. - var prev []byte - if len(buf.output) > 0 && buf.output[len(buf.output)-1].stderr { - prev = buf.output[len(buf.output)-1].data - buf.output = buf.output[:len(buf.output)-1] - } - buf.output = append(buf.output, outputEntry{ - stderr: true, - data: append(prev, data...), - }) + if len(buf.output) == 0 || !buf.output[len(buf.output)-1].stderr { + buf.output = append(buf.output, outputEntry{ + stderr: true, + }) + } + last := &buf.output[len(buf.output)-1] + last.data = append(last.data, data...) return len(data), nil } |