aboutsummaryrefslogtreecommitdiff
path: root/src/bytes/bytes.go
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2023-08-24 15:10:39 +0200
committerGopher Robot <gobot@golang.org>2023-08-25 15:08:28 +0000
commit890a62bf1b8022833d3cb616d3d7911b7f1d289a (patch)
tree342cf7087e823193b0092689329eb50ba43647ab /src/bytes/bytes.go
parent43559aa9a5a550ba7dac224a174130e42f93de99 (diff)
downloadgo-890a62bf1b8022833d3cb616d3d7911b7f1d289a.tar.xz
internal/bytealg: add generic LastIndexByte{,String}
To avoid duplicating them in net/netip and os and to allow these packages automatically benefiting from future performance improvements when optimized native LastIndexByte{,String} implementations are added. For #36891 Change-Id: I4905a4742273570c2c36b867df57762c5bfbe1e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/522475 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/bytes/bytes.go')
-rw-r--r--src/bytes/bytes.go9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go
index c54e52e4fc..7ecf3b59f6 100644
--- a/src/bytes/bytes.go
+++ b/src/bytes/bytes.go
@@ -112,7 +112,7 @@ func LastIndex(s, sep []byte) int {
case n == 0:
return len(s)
case n == 1:
- return LastIndexByte(s, sep[0])
+ return bytealg.LastIndexByte(s, sep[0])
case n == len(s):
if Equal(s, sep) {
return 0
@@ -144,12 +144,7 @@ func LastIndex(s, sep []byte) int {
// LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
func LastIndexByte(s []byte, c byte) int {
- for i := len(s) - 1; i >= 0; i-- {
- if s[i] == c {
- return i
- }
- }
- return -1
+ return bytealg.LastIndexByte(s, c)
}
// IndexRune interprets s as a sequence of UTF-8-encoded code points.