diff --git a/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go b/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go index 6790e615943..1c24cb0e977 100644 --- a/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go +++ b/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go @@ -144,11 +144,7 @@ func haveOverlap(a1, a2 []string) bool { if len(a1) > len(a2) { a1, a2 = a2, a1 } - m := make(sets.String) - - for _, val := range a1 { - m.Insert(val) - } + m := sets.New[string](a1...) for _, val := range a2 { if _, ok := m[val]; ok { return true diff --git a/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions_test.go b/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions_test.go index 7007db47616..a56516e2f74 100644 --- a/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions_test.go +++ b/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions_test.go @@ -359,6 +359,29 @@ func TestAccessModeConflicts(t *testing.T) { } } +func BenchmarkHaveOverlap(b *testing.B) { + tests := []struct { + a1 []string + a2 []string + isOverlap bool + }{ + { + a1: []string{"ab", "ac", "abc", "abcd", "abcde", "abcd", "ab", "abcdef", "abcdefg", "1", "2", "3", "4", "5", "6"}, + a2: []string{"bc", "helloworld", "bcd", "bcdef", "bcde", "12", "23", "34", "45", "56", "67", "78", "89"}, + isOverlap: false, + }, + } + testError := false + for n := 0; n < b.N; n++ { + for _, test := range tests { + if !testError && haveOverlap(test.a1, test.a2) != test.isOverlap { + testError = true + b.Errorf("test haveOverlap wrong, test case is: %v", test) + } + } + } +} + func newPlugin(ctx context.Context, t *testing.T) framework.Plugin { return newPluginWithListers(ctx, t, nil, nil, nil, true) }