@@ -10,16 +10,13 @@ import (
10
10
"slices"
11
11
)
12
12
13
- // TODO(adonovan): when https://go.dev/issue/32816 is accepted, all of
14
- // these functions should be annotated (provisionally with "//go:fix
15
- // inline") so that tools can safely and automatically replace calls
16
- // to exp/slices with calls to std slices by inlining them.
17
-
18
13
// Equal reports whether two slices are equal: the same length and all
19
14
// elements equal. If the lengths are different, Equal returns false.
20
15
// Otherwise, the elements are compared in increasing index order, and the
21
16
// comparison stops at the first unequal pair.
22
17
// Floating point NaNs are not considered equal.
18
+ //
19
+ //go:fix inline
23
20
func Equal [S ~ []E , E comparable ](s1 , s2 S ) bool {
24
21
return slices .Equal (s1 , s2 )
25
22
}
@@ -29,6 +26,8 @@ func Equal[S ~[]E, E comparable](s1, s2 S) bool {
29
26
// EqualFunc returns false. Otherwise, the elements are compared in
30
27
// increasing index order, and the comparison stops at the first index
31
28
// for which eq returns false.
29
+ //
30
+ //go:fix inline
32
31
func EqualFunc [S1 ~ []E1 , S2 ~ []E2 , E1 , E2 any ](s1 S1 , s2 S2 , eq func (E1 , E2 ) bool ) bool {
33
32
return slices .EqualFunc (s1 , s2 , eq )
34
33
}
@@ -40,6 +39,8 @@ func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) boo
40
39
// If both slices are equal until one of them ends, the shorter slice is
41
40
// considered less than the longer one.
42
41
// The result is 0 if s1 == s2, -1 if s1 < s2, and +1 if s1 > s2.
42
+ //
43
+ //go:fix inline
43
44
func Compare [S ~ []E , E cmp.Ordered ](s1 , s2 S ) int {
44
45
return slices .Compare (s1 , s2 )
45
46
}
@@ -49,29 +50,39 @@ func Compare[S ~[]E, E cmp.Ordered](s1, s2 S) int {
49
50
// The result is the first non-zero result of cmp; if cmp always
50
51
// returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2),
51
52
// and +1 if len(s1) > len(s2).
53
+ //
54
+ //go:fix inline
52
55
func CompareFunc [S1 ~ []E1 , S2 ~ []E2 , E1 , E2 any ](s1 S1 , s2 S2 , cmp func (E1 , E2 ) int ) int {
53
56
return slices .CompareFunc (s1 , s2 , cmp )
54
57
}
55
58
56
59
// Index returns the index of the first occurrence of v in s,
57
60
// or -1 if not present.
61
+ //
62
+ //go:fix inline
58
63
func Index [S ~ []E , E comparable ](s S , v E ) int {
59
64
return slices .Index (s , v )
60
65
}
61
66
62
67
// IndexFunc returns the first index i satisfying f(s[i]),
63
68
// or -1 if none do.
69
+ //
70
+ //go:fix inline
64
71
func IndexFunc [S ~ []E , E any ](s S , f func (E ) bool ) int {
65
72
return slices .IndexFunc (s , f )
66
73
}
67
74
68
75
// Contains reports whether v is present in s.
76
+ //
77
+ //go:fix inline
69
78
func Contains [S ~ []E , E comparable ](s S , v E ) bool {
70
79
return slices .Contains (s , v )
71
80
}
72
81
73
82
// ContainsFunc reports whether at least one
74
83
// element e of s satisfies f(e).
84
+ //
85
+ //go:fix inline
75
86
func ContainsFunc [S ~ []E , E any ](s S , f func (E ) bool ) bool {
76
87
return slices .ContainsFunc (s , f )
77
88
}
@@ -83,6 +94,8 @@ func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool {
83
94
// and r[i+len(v)] == value originally at r[i].
84
95
// Insert panics if i is out of range.
85
96
// This function is O(len(s) + len(v)).
97
+ //
98
+ //go:fix inline
86
99
func Insert [S ~ []E , E any ](s S , i int , v ... E ) S {
87
100
return slices .Insert (s , i , v ... )
88
101
}
@@ -92,26 +105,34 @@ func Insert[S ~[]E, E any](s S, i int, v ...E) S {
92
105
// Delete is O(len(s)-i), so if many items must be deleted, it is better to
93
106
// make a single call deleting them all together than to delete one at a time.
94
107
// Delete zeroes the elements s[len(s)-(j-i):len(s)].
108
+ //
109
+ //go:fix inline
95
110
func Delete [S ~ []E , E any ](s S , i , j int ) S {
96
111
return slices .Delete (s , i , j )
97
112
}
98
113
99
114
// DeleteFunc removes any elements from s for which del returns true,
100
115
// returning the modified slice.
101
116
// DeleteFunc zeroes the elements between the new length and the original length.
117
+ //
118
+ //go:fix inline
102
119
func DeleteFunc [S ~ []E , E any ](s S , del func (E ) bool ) S {
103
120
return slices .DeleteFunc (s , del )
104
121
}
105
122
106
123
// Replace replaces the elements s[i:j] by the given v, and returns the
107
124
// modified slice. Replace panics if s[i:j] is not a valid slice of s.
108
125
// When len(v) < (j-i), Replace zeroes the elements between the new length and the original length.
126
+ //
127
+ //go:fix inline
109
128
func Replace [S ~ []E , E any ](s S , i , j int , v ... E ) S {
110
129
return slices .Replace (s , i , j , v ... )
111
130
}
112
131
113
132
// Clone returns a copy of the slice.
114
133
// The elements are copied using assignment, so this is a shallow clone.
134
+ //
135
+ //go:fix inline
115
136
func Clone [S ~ []E , E any ](s S ) S {
116
137
return slices .Clone (s )
117
138
}
@@ -121,13 +142,17 @@ func Clone[S ~[]E, E any](s S) S {
121
142
// Compact modifies the contents of the slice s and returns the modified slice,
122
143
// which may have a smaller length.
123
144
// Compact zeroes the elements between the new length and the original length.
145
+ //
146
+ //go:fix inline
124
147
func Compact [S ~ []E , E comparable ](s S ) S {
125
148
return slices .Compact (s )
126
149
}
127
150
128
151
// CompactFunc is like [Compact] but uses an equality function to compare elements.
129
152
// For runs of elements that compare equal, CompactFunc keeps the first one.
130
153
// CompactFunc zeroes the elements between the new length and the original length.
154
+ //
155
+ //go:fix inline
131
156
func CompactFunc [S ~ []E , E any ](s S , eq func (E , E ) bool ) S {
132
157
return slices .CompactFunc (s , eq )
133
158
}
@@ -136,16 +161,22 @@ func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S {
136
161
// another n elements. After Grow(n), at least n elements can be appended
137
162
// to the slice without another allocation. If n is negative or too large to
138
163
// allocate the memory, Grow panics.
164
+ //
165
+ //go:fix inline
139
166
func Grow [S ~ []E , E any ](s S , n int ) S {
140
167
return slices .Grow (s , n )
141
168
}
142
169
143
170
// Clip removes unused capacity from the slice, returning s[:len(s):len(s)].
171
+ //
172
+ //go:fix inline
144
173
func Clip [S ~ []E , E any ](s S ) S {
145
174
return slices .Clip (s )
146
175
}
147
176
148
177
// Reverse reverses the elements of the slice in place.
178
+ //
179
+ //go:fix inline
149
180
func Reverse [S ~ []E , E any ](s S ) {
150
181
slices .Reverse (s )
151
182
}
0 commit comments