diff --git a/util/slice/slice.go b/util/slice/slice.go index 12738614a115f..078772d58c15a 100644 --- a/util/slice/slice.go +++ b/util/slice/slice.go @@ -39,16 +39,3 @@ func AllOf(s interface{}, p func(int) bool) bool { } return NoneOf(s, np) } - -// Copy is a deep copy of the slice. -func Copy[T any](a []*T) []*T { - b := make([]*T, len(a)) - for i, p := range a { - if p == nil { - continue - } - v := *p - b[i] = &v - } - return b -} diff --git a/util/slice/slice_test.go b/util/slice/slice_test.go index 787e0584c0f77..5a9b9ec17100f 100644 --- a/util/slice/slice_test.go +++ b/util/slice/slice_test.go @@ -43,19 +43,3 @@ func TestSlice(t *testing.T) { }) } } - -func TestCopy(t *testing.T) { - type T int - v0, v1, v2, v3 := T(0), T(1), T(2), T(3) - s := []*T{&v0, &v1, &v2, &v3, nil} - e := Copy(s) - require.Equal(t, len(s), len(e)) - for i := range s { - if s[i] == nil { - require.Nil(t, e[i]) - } else { - require.Equal(t, *s[i], *e[i]) - require.True(t, s[i] != e[i]) - } - } -} diff --git a/util/table-filter/BUILD.bazel b/util/table-filter/BUILD.bazel index 7c395d376cd36..7181e79254c93 100644 --- a/util/table-filter/BUILD.bazel +++ b/util/table-filter/BUILD.bazel @@ -5,7 +5,6 @@ go_library( srcs = [ "column_filter.go", "compat.go", - "helper.go", "matchers.go", "parser.go", "table_filter.go", diff --git a/util/table-filter/column_filter.go b/util/table-filter/column_filter.go index f8f06a09c8e4e..bbe82609272a0 100644 --- a/util/table-filter/column_filter.go +++ b/util/table-filter/column_filter.go @@ -14,7 +14,10 @@ package filter -import "strings" +import ( + "slices" + "strings" +) // ColumnFilter is a structure to check if a column should be included for processing. type ColumnFilter interface { @@ -43,7 +46,7 @@ func ParseColumnFilter(args []string) (ColumnFilter, error) { } } - reverse(p.rules) + slices.Reverse(p.rules) return columnFilter(p.rules), nil } diff --git a/util/table-filter/helper.go b/util/table-filter/helper.go deleted file mode 100644 index 27085caa5f81c..0000000000000 --- a/util/table-filter/helper.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021 PingCAP, Inc. -// -// 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 filter - -import "reflect" - -// reverse replace the contents of a slice with the same elements but in reverse order. -func reverse(items interface{}) { - n := reflect.ValueOf(items).Len() - swap := reflect.Swapper(items) - for i := n/2 - 1; i >= 0; i-- { - opp := n - 1 - i - swap(i, opp) - } -} diff --git a/util/table-filter/table_filter.go b/util/table-filter/table_filter.go index e6f237eb0be81..8f9fc35ad34e9 100644 --- a/util/table-filter/table_filter.go +++ b/util/table-filter/table_filter.go @@ -15,6 +15,7 @@ package filter import ( + "slices" "strings" ) @@ -48,7 +49,7 @@ func Parse(args []string) (Filter, error) { } } - reverse(p.rules) + slices.Reverse(p.rules) return tableFilter(p.rules), nil }