Skip to content

Commit a5c1904

Browse files
committed
assert.CallerInfo: micro optimization by using LastIndexByte
Use strings.LastIndexByte instead of strings.Split to extract the function name in CallerInfo. This reduces memory allocations.
1 parent 7127b60 commit a5c1904

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

assert/assertions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ func CallerInfo() []string {
266266
}
267267

268268
// Drop the package
269-
segments := strings.Split(name, ".")
270-
name = segments[len(segments)-1]
269+
dotPos := strings.LastIndexByte(name, '.')
270+
name = name[dotPos+1:]
271271
if isTest(name, "Test") ||
272272
isTest(name, "Benchmark") ||
273273
isTest(name, "Example") {

0 commit comments

Comments
 (0)