X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fslices%2Fslices.go;h=4c398557ff4241565f5ac776d28561cc53913abb;hb=7a1fce8751b04f66f758c7aac0efd5937bc670dc;hp=fe50a91d4844f38e517926f7e390126c218c64b0;hpb=1cc19e5ba0a008df7baeb78e076e43f9d8e0abf2;p=gostls13.git diff --git a/src/slices/slices.go b/src/slices/slices.go index fe50a91d48..4c398557ff 100644 --- a/src/slices/slices.go +++ b/src/slices/slices.go @@ -212,7 +212,7 @@ func Insert[S ~[]E, E any](s S, i int, v ...E) S { } // Delete removes the elements s[i:j] from s, returning the modified slice. -// Delete panics if s[i:j] is not a valid slice of s. +// Delete panics if j > len(s) or s[i:j] is not a valid slice of s. // Delete is O(len(s)-j), so if many items must be deleted, it is better to // make a single call deleting them all together than to delete one at a time. // Delete might not modify the elements s[len(s)-(j-i):len(s)]. If those @@ -246,9 +246,10 @@ func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S { } // Replace replaces the elements s[i:j] by the given v, and returns the -// modified slice. Replace panics if s[i:j] is not a valid slice of s. +// modified slice. +// Replace panics if j > len(s) or s[i:j] is not a valid slice of s. func Replace[S ~[]E, E any](s S, i, j int, v ...E) S { - _ = s[i:j] // verify that i:j is a valid subslice + _ = s[i:j] // bounds check if i == j { return Insert(s, i, v...)