]> Cypherpunks repositories - gostls13.git/commit
text/template: simplify unwrapping reflect.Interface value
authorJoe Taber <infogulch@gmail.com>
Mon, 18 Mar 2024 05:52:30 +0000 (05:52 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 18 Mar 2024 21:31:46 +0000 (21:31 +0000)
commit1ed85ee228023d766b37db056311929c00091c9f
tree90c01b1a6b70bdd06afff790783e8450e0727b89
parent3bd95485ad64fa4d1c3732ad3b8bcb142841dbb7
text/template: simplify unwrapping reflect.Interface value

When text/template is evaluating a pipeline command and encounters an
`interface{}`, it "digs down one level to the thing inside". Currently it
does this with `value = reflect.ValueOf(value.Interface())`, which is
unnecessary since it could just use `value = value.Elem()`. This commit
changes it to use the latter.

Why it was written that way is mysterious because the proposed change
appears to be strictly better, but given the blame date (13 years ago)
it may have been written while reflect was still in development before
`Elem()` was added.

Change-Id: I6c4f6283e78de07732c4120ce11f26f113fa46e4
GitHub-Last-Rev: bdfc6973ab227f951f244fda4d803da55fb49e71
GitHub-Pull-Request: golang/go#66373
Reviewed-on: https://go-review.googlesource.com/c/go/+/572355
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Rob Pike <r@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
src/text/template/exec.go