Set Capacity for Slices (#4540)

* set capacities

* make it more accurate

* resolve it
This commit is contained in:
Nishant Das 2020-01-14 14:44:24 +08:00 committed by GitHub
parent d2d4e7e35d
commit 0bee1de486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -396,7 +396,11 @@ func fetchBlockRootsBySlotRange(
return k != nil && bytes.Compare(k, max) <= 0
}
}
roots := make([][]byte, 0)
rootsRange := (endSlot - startSlot) / step
if endSlot < startSlot {
rootsRange = 0
}
roots := make([][]byte, 0, rootsRange)
c := bkt.Cursor()
for k, v := c.Seek(min); conditional(k, max); k, v = c.Next() {
if step > 1 {
@ -409,7 +413,8 @@ func fetchBlockRootsBySlotRange(
continue
}
}
splitRoots := make([][]byte, 0)
numOfRoots := len(v) / 32
splitRoots := make([][]byte, 0, numOfRoots)
for i := 0; i < len(v); i += 32 {
splitRoots = append(splitRoots, v[i:i+32])
}