diff options
| author | Marvin Stenger <marvin.stenger94@gmail.com> | 2017-09-25 15:47:44 +0200 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2017-09-27 00:54:24 +0000 |
| commit | d2826d3e068f096f4b5371175afb7e5d8c4aa73c (patch) | |
| tree | e252245e001e359351b9a06891cadf6d725231b9 /src/debug | |
| parent | e61c5e2f2044c7bc606ebdfbd0187598b90c50e5 (diff) | |
| download | go-d2826d3e068f096f4b5371175afb7e5d8c4aa73c.tar.xz | |
all: prefer strings.LastIndexByte over strings.LastIndex
strings.LastIndexByte was introduced in go1.5 and it can be used
effectively wherever the second argument to strings.LastIndex is
exactly one byte long.
This avoids generating unnecessary string symbols and saves
a few calls to strings.LastIndex.
Change-Id: I7b5679d616197b055cffe6882a8675d24a98b574
Reviewed-on: https://go-review.googlesource.com/66372
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/gosym/symtab.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/debug/gosym/symtab.go b/src/debug/gosym/symtab.go index b81f872801..eab255a359 100644 --- a/src/debug/gosym/symtab.go +++ b/src/debug/gosym/symtab.go @@ -40,7 +40,7 @@ func (s *Sym) Static() bool { return s.Type >= 'a' } // PackageName returns the package part of the symbol name, // or the empty string if there is none. func (s *Sym) PackageName() string { - pathend := strings.LastIndex(s.Name, "/") + pathend := strings.LastIndexByte(s.Name, '/') if pathend < 0 { pathend = 0 } @@ -54,12 +54,12 @@ func (s *Sym) PackageName() string { // ReceiverName returns the receiver type name of this symbol, // or the empty string if there is none. func (s *Sym) ReceiverName() string { - pathend := strings.LastIndex(s.Name, "/") + pathend := strings.LastIndexByte(s.Name, '/') if pathend < 0 { pathend = 0 } l := strings.IndexByte(s.Name[pathend:], '.') - r := strings.LastIndex(s.Name[pathend:], ".") + r := strings.LastIndexByte(s.Name[pathend:], '.') if l == -1 || r == -1 || l == r { return "" } @@ -68,7 +68,7 @@ func (s *Sym) ReceiverName() string { // BaseName returns the symbol name without the package or receiver name. func (s *Sym) BaseName() string { - if i := strings.LastIndex(s.Name, "."); i != -1 { + if i := strings.LastIndexByte(s.Name, '.'); i != -1 { return s.Name[i+1:] } return s.Name |
