mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
all: remove LenIter, use Go 1.22 range-over-int instead
Updates #11058 Updates golang/go#65685 Change-Id: Ibb216b346e511d486271ab3d84e4546c521e4e22 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
ff1391a97e
commit
e1bd7488d0
@@ -77,11 +77,6 @@ func (v ByteSlice[T]) AppendTo(dst T) T {
|
||||
return append(dst, v.ж...)
|
||||
}
|
||||
|
||||
// LenIter returns a slice the same length as the v.Len().
|
||||
// The caller can then range over it to get the valid indexes.
|
||||
// It does not allocate.
|
||||
func (v ByteSlice[T]) LenIter() []struct{} { return make([]struct{}, len(v.ж)) }
|
||||
|
||||
// At returns the byte at index `i` of the slice.
|
||||
func (v ByteSlice[T]) At(i int) byte { return v.ж[i] }
|
||||
|
||||
@@ -154,11 +149,6 @@ func (v SliceView[T, V]) IsNil() bool { return v.ж == nil }
|
||||
// Len returns the length of the slice.
|
||||
func (v SliceView[T, V]) Len() int { return len(v.ж) }
|
||||
|
||||
// LenIter returns a slice the same length as the v.Len().
|
||||
// The caller can then range over it to get the valid indexes.
|
||||
// It does not allocate.
|
||||
func (v SliceView[T, V]) LenIter() []struct{} { return make([]struct{}, len(v.ж)) }
|
||||
|
||||
// At returns a View of the element at index `i` of the slice.
|
||||
func (v SliceView[T, V]) At(i int) V { return v.ж[i].View() }
|
||||
|
||||
@@ -245,11 +235,6 @@ func (v Slice[T]) IsNil() bool { return v.ж == nil }
|
||||
// Len returns the length of the slice.
|
||||
func (v Slice[T]) Len() int { return len(v.ж) }
|
||||
|
||||
// LenIter returns a slice the same length as the v.Len().
|
||||
// The caller can then range over it to get the valid indexes.
|
||||
// It does not allocate.
|
||||
func (v Slice[T]) LenIter() []struct{} { return make([]struct{}, len(v.ж)) }
|
||||
|
||||
// At returns the element at index `i` of the slice.
|
||||
func (v Slice[T]) At(i int) T { return v.ж[i] }
|
||||
|
||||
|
@@ -141,27 +141,6 @@ func TestViewUtils(t *testing.T) {
|
||||
qt.Equals, true)
|
||||
}
|
||||
|
||||
func TestLenIter(t *testing.T) {
|
||||
orig := []string{"foo", "bar"}
|
||||
var got []string
|
||||
v := SliceOf(orig)
|
||||
for i := range v.LenIter() {
|
||||
got = append(got, v.At(i))
|
||||
}
|
||||
if !reflect.DeepEqual(orig, got) {
|
||||
t.Errorf("got %q; want %q", got, orig)
|
||||
}
|
||||
x := 0
|
||||
n := testing.AllocsPerRun(10000, func() {
|
||||
for range v.LenIter() {
|
||||
x++
|
||||
}
|
||||
})
|
||||
if n > 0 {
|
||||
t.Errorf("allocs = %v; want 0", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSliceEqual(t *testing.T) {
|
||||
a := SliceOf([]string{"foo", "bar"})
|
||||
b := SliceOf([]string{"foo", "bar"})
|
||||
|
Reference in New Issue
Block a user