Skip to content

Commit 272358c

Browse files
authored
huff0: Reduce bounds checking (#734)
Apparently, Go 1.19 understands that v := b.in[b.off-4 : b.off] has length four, but then inserts an additional check for v = v[:4]. Removing the latter ensures the comments saying "2 bounds checks" are correct again (two checks in a single line).
1 parent ded586e commit 272358c

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

huff0/bitreader.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (b *bitReaderBytes) fillFast() {
6767

6868
// 2 bounds checks.
6969
v := b.in[b.off-4 : b.off]
70-
v = v[:4]
7170
low := (uint32(v[0])) | (uint32(v[1]) << 8) | (uint32(v[2]) << 16) | (uint32(v[3]) << 24)
7271
b.value |= uint64(low) << (b.bitsRead - 32)
7372
b.bitsRead -= 32
@@ -88,8 +87,7 @@ func (b *bitReaderBytes) fill() {
8887
return
8988
}
9089
if b.off > 4 {
91-
v := b.in[b.off-4:]
92-
v = v[:4]
90+
v := b.in[b.off-4 : b.off]
9391
low := (uint32(v[0])) | (uint32(v[1]) << 8) | (uint32(v[2]) << 16) | (uint32(v[3]) << 24)
9492
b.value |= uint64(low) << (b.bitsRead - 32)
9593
b.bitsRead -= 32
@@ -179,7 +177,6 @@ func (b *bitReaderShifted) fillFast() {
179177

180178
// 2 bounds checks.
181179
v := b.in[b.off-4 : b.off]
182-
v = v[:4]
183180
low := (uint32(v[0])) | (uint32(v[1]) << 8) | (uint32(v[2]) << 16) | (uint32(v[3]) << 24)
184181
b.value |= uint64(low) << ((b.bitsRead - 32) & 63)
185182
b.bitsRead -= 32
@@ -200,8 +197,7 @@ func (b *bitReaderShifted) fill() {
200197
return
201198
}
202199
if b.off > 4 {
203-
v := b.in[b.off-4:]
204-
v = v[:4]
200+
v := b.in[b.off-4 : b.off]
205201
low := (uint32(v[0])) | (uint32(v[1]) << 8) | (uint32(v[2]) << 16) | (uint32(v[3]) << 24)
206202
b.value |= uint64(low) << ((b.bitsRead - 32) & 63)
207203
b.bitsRead -= 32

0 commit comments

Comments
 (0)