From e5d9cafbe8aa071eb76020ae77a1ae090eac2a7e Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 30 Jun 2015 14:02:04 +1000 Subject: [PATCH] compress/lzw: tidy up some flush calls. Change-Id: Ie7368188ad4a970a82c140962cf97347d24f0331 Reviewed-on: https://go-review.googlesource.com/14410 Reviewed-by: David Symonds --- src/compress/lzw/reader.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/compress/lzw/reader.go b/src/compress/lzw/reader.go index 1353831eca9d8a..9eef2b2a782b7c 100644 --- a/src/compress/lzw/reader.go +++ b/src/compress/lzw/reader.go @@ -132,6 +132,7 @@ func (d *decoder) Read(b []byte) (int, error) { // litWidth is the width in bits of literal codes. func (d *decoder) decode() { // Loop over the code stream, converting codes into decompressed bytes. +loop: for { code, err := d.read(d) if err != nil { @@ -139,8 +140,7 @@ func (d *decoder) decode() { err = io.ErrUnexpectedEOF } d.err = err - d.flush() - return + break } switch { case code < d.clear: @@ -159,9 +159,8 @@ func (d *decoder) decode() { d.last = decoderInvalidCode continue case code == d.eof: - d.flush() d.err = io.EOF - return + break loop case code <= d.hi: c, i := code, len(d.output)-1 if code == d.hi { @@ -191,8 +190,7 @@ func (d *decoder) decode() { } default: d.err = errors.New("lzw: invalid code") - d.flush() - return + break loop } d.last, d.hi = code, d.hi+1 if d.hi >= d.overflow { @@ -204,13 +202,10 @@ func (d *decoder) decode() { } } if d.o >= flushBuffer { - d.flush() - return + break } } -} - -func (d *decoder) flush() { + // Flush pending output. d.toRead = d.output[:d.o] d.o = 0 }