From 1817d86aece1599208ab10e7fd21ac828f63e45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 16 Jun 2025 16:06:59 +0200 Subject: [PATCH] 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. --- assert/assertions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 0514a154e..5e9cb6e5d 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -266,8 +266,8 @@ func CallerInfo() []string { } // Drop the package - segments := strings.Split(name, ".") - name = segments[len(segments)-1] + dotPos := strings.LastIndexByte(name, '.') + name = name[dotPos+1:] if isTest(name, "Test") || isTest(name, "Benchmark") || isTest(name, "Example") {