Skip to content

Commit

Permalink
compress/lzw: tidy up some flush calls.
Browse files Browse the repository at this point in the history
Change-Id: Ie7368188ad4a970a82c140962cf97347d24f0331
Reviewed-on: https://go-review.googlesource.com/14410
Reviewed-by: David Symonds <[email protected]>
  • Loading branch information
nigeltao committed Sep 9, 2015
1 parent f7b66ff commit e5d9caf
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/compress/lzw/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ 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 {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
d.err = err
d.flush()
return
break
}
switch {
case code < d.clear:
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit e5d9caf

Please sign in to comment.