Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor P-chain Builder #3282

Merged
merged 11 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions snow/engine/snowman/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ava-labs/avalanchego/snow/engine/snowman/getter"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/version"
)
Expand Down Expand Up @@ -3078,7 +3079,7 @@ func TestShouldIssueBlock(t *testing.T) {
chain4Through6 = snowmantest.BuildDescendants(chain0Through3[0], 3)
chain7Through10 = snowmantest.BuildDescendants(snowmantest.Genesis, 4)
chain11Through11 = snowmantest.BuildDescendants(chain7Through10[1], 1)
blocks = join(chain0Through3, chain4Through6, chain7Through10, chain11Through11)
blocks = utils.Join(chain0Through3, chain4Through6, chain7Through10, chain11Through11)
)

require.NoError(t, blocks[0].Accept(context.Background()))
Expand Down Expand Up @@ -3181,18 +3182,3 @@ func TestShouldIssueBlock(t *testing.T) {
})
}
}

// join the provided slices into a single slice.
//
// TODO: Use slices.Concat once the minimum go version is 1.22.
func join[T any](slices ...[]T) []T {
size := 0
for _, s := range slices {
size += len(s)
}
newSlice := make([]T, 0, size)
for _, s := range slices {
newSlice = append(newSlice, s...)
}
return newSlice
}
19 changes: 19 additions & 0 deletions utils/slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package utils

// Join merges the provided slices into a single slice.
//
// TODO: Use slices.Concat once the minimum go version is 1.22.
Copy link
Contributor

@ARR4N ARR4N Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(no action required) Their signature is interesting:

func Concat[S ~[]E, E any](slices ...S) S {

Without looking too deeply I guess it's to play nicely with other functions in that package / make it easier to use them together without being confused about which type is which.

func Join[T any](slices ...[]T) []T {
size := 0
for _, s := range slices {
size += len(s)
}
newSlice := make([]T, 0, size)
for _, s := range slices {
newSlice = append(newSlice, s...)
}
return newSlice
}
Loading
Loading