mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Improve performance of method haveOverlap
Signed-off-by: mantuliu <240951888@qq.com>
This commit is contained in:
parent
487c443239
commit
e1e07e34e3
@ -144,11 +144,7 @@ func haveOverlap(a1, a2 []string) bool {
|
|||||||
if len(a1) > len(a2) {
|
if len(a1) > len(a2) {
|
||||||
a1, a2 = a2, a1
|
a1, a2 = a2, a1
|
||||||
}
|
}
|
||||||
m := make(sets.String)
|
m := sets.New[string](a1...)
|
||||||
|
|
||||||
for _, val := range a1 {
|
|
||||||
m.Insert(val)
|
|
||||||
}
|
|
||||||
for _, val := range a2 {
|
for _, val := range a2 {
|
||||||
if _, ok := m[val]; ok {
|
if _, ok := m[val]; ok {
|
||||||
return true
|
return true
|
||||||
|
@ -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 {
|
func newPlugin(ctx context.Context, t *testing.T) framework.Plugin {
|
||||||
return newPluginWithListers(ctx, t, nil, nil, nil, true)
|
return newPluginWithListers(ctx, t, nil, nil, nil, true)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user