Commit e5d9cafb authored by Nigel Tao's avatar Nigel Tao

compress/lzw: tidy up some flush calls.

Change-Id: Ie7368188ad4a970a82c140962cf97347d24f0331
Reviewed-on: https://go-review.googlesource.com/14410Reviewed-by: 's avatarDavid Symonds <dsymonds@golang.org>
parent f7b66fff
...@@ -132,6 +132,7 @@ func (d *decoder) Read(b []byte) (int, error) { ...@@ -132,6 +132,7 @@ func (d *decoder) Read(b []byte) (int, error) {
// litWidth is the width in bits of literal codes. // litWidth is the width in bits of literal codes.
func (d *decoder) decode() { func (d *decoder) decode() {
// Loop over the code stream, converting codes into decompressed bytes. // Loop over the code stream, converting codes into decompressed bytes.
loop:
for { for {
code, err := d.read(d) code, err := d.read(d)
if err != nil { if err != nil {
...@@ -139,8 +140,7 @@ func (d *decoder) decode() { ...@@ -139,8 +140,7 @@ func (d *decoder) decode() {
err = io.ErrUnexpectedEOF err = io.ErrUnexpectedEOF
} }
d.err = err d.err = err
d.flush() break
return
} }
switch { switch {
case code < d.clear: case code < d.clear:
...@@ -159,9 +159,8 @@ func (d *decoder) decode() { ...@@ -159,9 +159,8 @@ func (d *decoder) decode() {
d.last = decoderInvalidCode d.last = decoderInvalidCode
continue continue
case code == d.eof: case code == d.eof:
d.flush()
d.err = io.EOF d.err = io.EOF
return break loop
case code <= d.hi: case code <= d.hi:
c, i := code, len(d.output)-1 c, i := code, len(d.output)-1
if code == d.hi { if code == d.hi {
...@@ -191,8 +190,7 @@ func (d *decoder) decode() { ...@@ -191,8 +190,7 @@ func (d *decoder) decode() {
} }
default: default:
d.err = errors.New("lzw: invalid code") d.err = errors.New("lzw: invalid code")
d.flush() break loop
return
} }
d.last, d.hi = code, d.hi+1 d.last, d.hi = code, d.hi+1
if d.hi >= d.overflow { if d.hi >= d.overflow {
...@@ -204,13 +202,10 @@ func (d *decoder) decode() { ...@@ -204,13 +202,10 @@ func (d *decoder) decode() {
} }
} }
if d.o >= flushBuffer { if d.o >= flushBuffer {
d.flush() break
return
} }
} }
} // Flush pending output.
func (d *decoder) flush() {
d.toRead = d.output[:d.o] d.toRead = d.output[:d.o]
d.o = 0 d.o = 0
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment