]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: preallocate panic errors for index and slice
authorRuss Cox <rsc@golang.org>
Sat, 30 Aug 2014 18:18:41 +0000 (14:18 -0400)
committerRuss Cox <rsc@golang.org>
Sat, 30 Aug 2014 18:18:41 +0000 (14:18 -0400)
This avoids allocating at the panic sites.

LGTM=r, khr
R=golang-codereviews, r, khr
CC=dvyukov, golang-codereviews, iant, khr
https://golang.org/cl/136020043

src/pkg/runtime/panic.go

index ac0c6b77ee6007ed28bd1cbfcb8f5a2dda281cbd..9b95f496737203ddbbdf5d74c222171e8dc28485 100644 (file)
@@ -4,10 +4,14 @@
 
 package runtime
 
+var indexError = error(errorString("index out of range"))
+
 func panicindex() {
-       panic(errorString("index out of range"))
+       panic(indexError)
 }
 
+var sliceError = error(errorString("slice bounds out of range"))
+
 func panicslice() {
-       panic(errorString("slice bounds out of range"))
+       panic(sliceError)
 }