cleanup: use slices.Equal to simplify code (#8472)
diff --git a/xds/internal/balancer/clusterimpl/clusterimpl.go b/xds/internal/balancer/clusterimpl/clusterimpl.go
index 096b738..006be4c 100644
--- a/xds/internal/balancer/clusterimpl/clusterimpl.go
+++ b/xds/internal/balancer/clusterimpl/clusterimpl.go
@@ -27,6 +27,7 @@
"context"
"encoding/json"
"fmt"
+ "slices"
"sync"
"sync/atomic"
"time"
@@ -128,7 +129,7 @@
// indicating if a new picker needs to be generated.
func (b *clusterImplBalancer) handleDropAndRequestCountLocked(newConfig *LBConfig) bool {
var updatePicker bool
- if !equalDropCategories(b.dropCategories, newConfig.DropCategories) {
+ if !slices.Equal(b.dropCategories, newConfig.DropCategories) {
b.dropCategories = newConfig.DropCategories
b.drops = make([]*dropper, 0, len(newConfig.DropCategories))
for _, c := range newConfig.DropCategories {
diff --git a/xds/internal/balancer/clusterimpl/config.go b/xds/internal/balancer/clusterimpl/config.go
index 134a568..34f777a 100644
--- a/xds/internal/balancer/clusterimpl/config.go
+++ b/xds/internal/balancer/clusterimpl/config.go
@@ -55,15 +55,3 @@
}
return &cfg, nil
}
-
-func equalDropCategories(a, b []DropConfig) bool {
- if len(a) != len(b) {
- return false
- }
- for i := range a {
- if a[i] != b[i] {
- return false
- }
- }
- return true
-}
diff --git a/xds/internal/balancer/priority/utils.go b/xds/internal/balancer/priority/utils.go
deleted file mode 100644
index 45fbe76..0000000
--- a/xds/internal/balancer/priority/utils.go
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *
- * Copyright 2021 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package priority
-
-func equalStringSlice(a, b []string) bool {
- if len(a) != len(b) {
- return false
- }
- for i := range a {
- if a[i] != b[i] {
- return false
- }
- }
- return true
-}
diff --git a/xds/internal/balancer/priority/utils_test.go b/xds/internal/balancer/priority/utils_test.go
deleted file mode 100644
index c80a89b..0000000
--- a/xds/internal/balancer/priority/utils_test.go
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *
- * Copyright 2021 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package priority
-
-import "testing"
-
-func TestCompareStringSlice(t *testing.T) {
- tests := []struct {
- name string
- a []string
- b []string
- want bool
- }{
- {
- name: "equal",
- a: []string{"a", "b"},
- b: []string{"a", "b"},
- want: true,
- },
- {
- name: "not equal",
- a: []string{"a", "b"},
- b: []string{"a", "b", "c"},
- want: false,
- },
- {
- name: "both empty",
- a: nil,
- b: nil,
- want: true,
- },
- {
- name: "one empty",
- a: []string{"a", "b"},
- b: nil,
- want: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got := equalStringSlice(tt.a, tt.b); got != tt.want {
- t.Errorf("equalStringSlice(%v, %v) = %v, want %v", tt.a, tt.b, got, tt.want)
- }
- })
- }
-}