Skip to content

Commit e6c9379

Browse files
committed
meta: remove tail zero slice in compactChunk
1 parent 6c5f5e9 commit e6c9379

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pkg/meta/slice.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,20 @@ func buildSlice(ss []*slice) []Slice {
157157
func compactChunk(ss []*slice) (uint32, uint32, []Slice) {
158158
var chunk = buildSlice(ss)
159159
var pos uint32
160-
for len(chunk) > 1 && chunk[0].Id == 0 {
161-
pos += chunk[0].Len
162-
chunk = chunk[1:]
160+
n := len(chunk)
161+
for n > 1 {
162+
if chunk[0].Id == 0 {
163+
pos += chunk[0].Len
164+
chunk = chunk[1:]
165+
n--
166+
} else if chunk[n-1].Id == 0 {
167+
chunk = chunk[:n-1]
168+
n--
169+
} else {
170+
break
171+
}
163172
}
164-
if len(chunk) == 1 && chunk[0].Id == 0 {
173+
if n == 1 && chunk[0].Id == 0 {
165174
chunk[0].Len = 1
166175
}
167176
var size uint32

0 commit comments

Comments
 (0)