attestationutil.AttestingIndices: Minor improvement on indices array allocation (#6508)

* attestationutil.AttestingIndices: Minor improvement on indices array allocation
* Merge branch 'master' of github.com:prysmaticlabs/prysm into HEAD
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
* Merge refs/heads/master into memory1
This commit is contained in:
Preston Van Loon 2020-07-08 02:57:50 -07:00 committed by GitHub
parent a279f18461
commit f2f2677070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -67,7 +67,7 @@ func ConvertToIndexed(ctx context.Context, attestation *ethpb.Attestation, commi
// committee = get_beacon_committee(state, data.slot, data.index)
// return set(index for i, index in enumerate(committee) if bits[i])
func AttestingIndices(bf bitfield.Bitfield, committee []uint64) []uint64 {
indices := make([]uint64, 0, len(committee))
indices := make([]uint64, 0, bf.Count())
for _, idx := range bf.BitIndices() {
if idx < len(committee) {
indices = append(indices, committee[idx])

View File

@ -114,9 +114,10 @@ func TestIsValidAttestationIndices(t *testing.T) {
}
func BenchmarkAttestingIndices_PartialCommittee(b *testing.B) {
bf := bitfield.Bitlist{0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b100}
bf := bitfield.Bitlist{0b11111111, 0b11111111, 0b10000111, 0b11111111, 0b100}
committee := []uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = attestationutil.AttestingIndices(bf, committee)
}