]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/types: simplify and optimize PtrDataSize
authorMatthew Dempsky <mdempsky@google.com>
Sat, 28 Aug 2021 00:14:00 +0000 (17:14 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 28 Aug 2021 00:50:13 +0000 (00:50 +0000)
commitc81fa001a7b01be5ce9d2990e706f0ed2c1299e8
tree5246748d736e3ccb31d631376e2431a653893f90
parenta9377183d0f3ccd49631e2d927d55d91f2ab5ec6
cmd/compile/internal/types: simplify and optimize PtrDataSize

The current implementation of PtrDataSize checks HasPointers each
call, which could lead to exponential blow-up in handling (admittedly
contrived) deeply nested structs.

To avoid the duplicate recursion, this CL incorporates the HasPointers
logic directly int PtrDataSize, and then re-defines HasPointers as
simply "PtrDataSize(t) > 0".

This CL also tightens up HasPointers/PtrDataSize to only be valid on
actual Go types. Fortunately, there was only one instance where this
wasn't already the case (escape analysis), and that's easily fixed
with an extra check for untyped types.

Change-Id: I0044bf9b558a88333aee2ccb137afb6cb4fea1db
Reviewed-on: https://go-review.googlesource.com/c/go/+/345809
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/escape/expr.go
src/cmd/compile/internal/types/size.go
src/cmd/compile/internal/types/type.go