mirror of
https://github.com/golang/go.git
synced 2026-04-03 01:40:30 +09:00
cmd/compile: test that time.Duration.String is inlineable
This matters for encodings supporting time.Duration,
which cannot add an AppendText method due to the encoding package godoc:
Adding encoding/decoding methods to existing types may constitute
a breaking change, [...] The policy for packages maintained by
the Go project is to only allow the addition of marshaling functions
if no existing, reasonable marshaling exists.
And indeed, time.Duration does have an existing marshaling today:
as an integer, which encoding/json still uses to this day.
Thankfully, with the String method being inlineable, we can rely on
the following not allocating in the heap:
var td time.Duration = ...
b = append(b, td.String()...)
Lock this in so that we can rely on this pattern going forward.
For #77851.
Change-Id: I57ce0bc099f293b0e36aa4c74b5410f8bda347a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/750100
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
committed by
Gopher Robot
parent
244b156e67
commit
fea0300499
@@ -233,6 +233,9 @@ func TestIntendedInlining(t *testing.T) {
|
||||
"testing": {
|
||||
"(*B).Loop",
|
||||
},
|
||||
"time": {
|
||||
"Duration.String",
|
||||
},
|
||||
"path": {
|
||||
"Base",
|
||||
"scanChunk",
|
||||
|
||||
Reference in New Issue
Block a user