]> Cypherpunks repositories - gostls13.git/commit
reflect: avoid TypeOf in init
authorJoe Tsai <joetsai@digital-static.net>
Thu, 28 Jul 2022 06:19:40 +0000 (23:19 -0700)
committerJoseph Tsai <joetsai@digital-static.net>
Mon, 8 Aug 2022 17:36:35 +0000 (17:36 +0000)
commitebf182c82de21858a1a167cc8d252ae85de806a7
tree367d5fd30d8a38dfc15b47b837c57c821434a635
parent84be09104883b6cf5d53e32f85834d5e71e954fa
reflect: avoid TypeOf in init

Calling TypeOf to initialize variables forces any import of "reflect"
to link in the declared types of "reflect" even if they are unused.
TypeOf operates on Type and which will pull in
all transitive dependencies of Type, which includes Value as well.
Avoid this problem by declaring a rtypeOf function that
directly extracts the *rtype from an interface value
without going through Type as an intermediate type.

For a program that blank imports "reflect",
this reduces the binary size by ~34 KiB.

Updates #54097

Change-Id: I8dc7d8da8fedc48cc0dd842b69f510d17144827e
Reviewed-on: https://go-review.googlesource.com/c/go/+/419757
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/reflect/type.go
src/reflect/value.go