Skip to content

Commit 4e21555

Browse files
committed
compress/lzw: clarify code invariants
This follows on from https://go-review.googlesource.com/c/go/+/191358 which was submitted as a comment-only change. Benchmarks don't show any significant change: compress/lzw name old speed new speed delta Decoder/1e4-56 92.8MB/s ± 1% 92.7MB/s ± 1% ~ (p=1.000 n=5+5) Decoder/1e5-56 100MB/s ± 1% 100MB/s ± 1% ~ (p=0.746 n=5+5) Decoder/1e6-56 101MB/s ± 1% 101MB/s ± 1% ~ (p=0.381 n=5+5) image/gif name old speed new speed delta Decode-56 63.2MB/s ± 1% 63.2MB/s ± 1% ~ (p=0.690 n=5+5) Change-Id: Ic36b5410cb06ca258da32e40da1f1ff6c44cff86 Reviewed-on: https://go-review.googlesource.com/c/go/+/194938 Reviewed-by: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 8cc57c0 commit 4e21555

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/compress/lzw/reader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ loop:
199199
}
200200
d.last, d.hi = code, d.hi+1
201201
if d.hi >= d.overflow {
202+
if d.hi > d.overflow {
203+
panic("unreachable")
204+
}
202205
if d.width == maxWidth {
203206
d.last = decoderInvalidCode
204207
// Undo the d.hi++ a few lines above, so that (1) we maintain
@@ -207,7 +210,7 @@ loop:
207210
d.hi--
208211
} else {
209212
d.width++
210-
d.overflow <<= 1
213+
d.overflow = 1 << d.width
211214
}
212215
}
213216
if d.o >= flushBuffer {

0 commit comments

Comments
 (0)