From 9c2fd81ee11c1c49e55f1c59a96e170f2d53e6c8 Mon Sep 17 00:00:00 2001 From: Tomasz Jezierski Date: Fri, 30 Sep 2022 16:17:45 +0200 Subject: [PATCH] encoding/asn1: remove allocation from init asn1 allocates due to reflect.TypeOf(new(big.Int)) in init time. We could replace it with (*big.Int)(nil). Before: init encoding/asn1 @1.0 ms, 0.009 ms clock, 224 bytes, 7 allocs After: init encoding/asn1 @0.70 ms, 0.002 ms clock, 192 bytes, 6 allocs Fixes #55973 Change-Id: I7c3cc0f48631af73cf34ad3c731c380f46c72359 Reviewed-on: https://go-review.googlesource.com/c/go/+/435257 Run-TryBot: Dmitri Shuralyov TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: hopehook Auto-Submit: Ian Lance Taylor --- src/encoding/asn1/asn1.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/encoding/asn1/asn1.go b/src/encoding/asn1/asn1.go index 6a7aa473a5..2e320897e3 100644 --- a/src/encoding/asn1/asn1.go +++ b/src/encoding/asn1/asn1.go @@ -660,7 +660,7 @@ var ( timeType = reflect.TypeOf(time.Time{}) rawValueType = reflect.TypeOf(RawValue{}) rawContentsType = reflect.TypeOf(RawContent(nil)) - bigIntType = reflect.TypeOf(new(big.Int)) + bigIntType = reflect.TypeOf((*big.Int)(nil)) ) // invalidLength reports whether offset + length > sliceLength, or if the