aboutsummaryrefslogtreecommitdiff
path: root/src/errors
diff options
context:
space:
mode:
authorMarcel van Lohuizen <mpvl@golang.org>2019-03-13 16:47:44 +0100
committerMarcel van Lohuizen <mpvl@golang.org>2019-03-14 09:32:11 +0000
commit8bf18b56a47a98b9dd2fa03beb358312237a8c76 (patch)
treefedb1876467c7a77119df7a10afe71205989c28d /src/errors
parent5402854c3557f87fa2741a52ffc15dfb1ef333cc (diff)
downloadgo-8bf18b56a47a98b9dd2fa03beb358312237a8c76.tar.gz
go-8bf18b56a47a98b9dd2fa03beb358312237a8c76.zip
errors: improve performance of New
See Issue #29382 and Issue #30468. Improvements in this CL: name old time/op new time/op delta New-8 352ns ± 2% 225ns ± 5% -36.04% (p=0.008 n=5+5) Improvements together with moving to 1 uintptr: name old time/op new time/op delta New-8 475ns ± 3% 225ns ± 5% -52.59% (p=0.008 n=5+5) Change-Id: I9d69a14e5e10a6498767defb7d5f26ceedcf9ba5 Reviewed-on: https://go-review.googlesource.com/c/go/+/167401 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/errors')
-rw-r--r--src/errors/errors.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/errors/errors.go b/src/errors/errors.go
index f23a96c43e..ebb136cdd4 100644
--- a/src/errors/errors.go
+++ b/src/errors/errors.go
@@ -5,12 +5,17 @@
// Package errors implements functions to manipulate errors.
package errors
+import "runtime"
+
// New returns an error that formats as the given text.
//
// The returned error contains a Frame set to the caller's location and
// implements Formatter to show this information when printed with details.
func New(text string) error {
- return &errorString{text, Caller(1)}
+ // Inline call to errors.Callers to improve performance.
+ var s Frame
+ runtime.Callers(2, s.frames[:])
+ return &errorString{text, s}
}
// errorString is a trivial implementation of error.