]> Cypherpunks repositories - gostls13.git/commit
reflect: avoid unnecessary copy of funcTypes
authorZeke Lu <lvzecai@gmail.com>
Tue, 4 Oct 2022 07:10:09 +0000 (07:10 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 4 Oct 2022 23:15:54 +0000 (23:15 +0000)
commite7d203f494281a229a7d4ef769f14975e9b12e4e
treeb89e9726ceb1bbc50ebae8f4832ec2bc1957dacb
parent58158e990f272774e615c9abd8662bf0198c29aa
reflect: avoid unnecessary copy of funcTypes

Imagine that initFuncTypes is called with n=3, funcTypes will be
[nil, nil, nil, **reflect.rtype] afterward, then it's called with n=2.
The current implementation will copy funcTypes because funcTypes[2] is
nil. This is unnecessary. It should make a new slice and copy funcTypes
into it only when n >= len(funcTypes).

Updates #56011.

Change-Id: Ia093d2f550d6924a4c58bcd21325093e32b40baa
GitHub-Last-Rev: a599eae7c2f6a388dfe1ff39cf61fd645885a64d
GitHub-Pull-Request: golang/go#56024
Reviewed-on: https://go-review.googlesource.com/c/go/+/438395
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/reflect/type.go