1
0
mirror of https://github.com/golang/go synced 2024-10-04 03:11:22 -06:00
Commit Graph

5 Commits

Author SHA1 Message Date
Justin Nuß
5f859ba83d time: Use AppendFormat in Marshal[Text|JSON]
The current implementations of MarshalJSON and MarshalText use
time.Format which returns a string (converted from a byte slice),
only to convert it back to a byte slice.

Avoid the conversion (and thus an allocation) by directly appending
the formatted time to a preallocated byte slice, using the new
AppendFormat function, introduced in golang.org/cl/1760.

This reduces the allocations done in Marshal[Text|JSON] by 50%.

benchmark                old ns/op     new ns/op     delta
BenchmarkMarshalJSON     626           507           -19.01%
BenchmarkMarshalText     598           511           -14.55%

benchmark                old allocs     new allocs     delta
BenchmarkMarshalJSON     2              1              -50.00%
BenchmarkMarshalText     2              1              -50.00%

benchmark                old bytes     new bytes     delta
BenchmarkMarshalJSON     96            48            -50.00%
BenchmarkMarshalText     96            48            -50.00%

Fixes #11025

Change-Id: I468f78d075a6ecc1cdc839df7fb407fbc6ff2e70
Reviewed-on: https://go-review.googlesource.com/10555
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-22 11:31:58 +00:00
Shenghou Ma
526b501713 time: correct unrepresentable Unix time comment
It's easy for someone who wants a time bigger than any
valid time to reach for time.Unix(1<<63-1, 0), so it
makes sense to explicit say such value is not valid.

Fixes #10906 (again).

Change-Id: If71e32472ae40d86c30e629b982406040a73c4c7
Reviewed-on: https://go-review.googlesource.com/10266
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-18 18:21:59 +00:00
Shenghou Ma
f3fc8b0245 time: document that not all Unix time can be represented
Fixes #10906.

Change-Id: I7ae25a500df493c1e78183d69d89b3e2a64a0d1a
Reviewed-on: https://go-review.googlesource.com/10223
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-05-19 06:19:33 +00:00
Rob Pike
cfae41ff36 time: make it clear that time.Time values do not compare with ==
LGTM=bradfitz, josharian, adg, rsc
R=golang-codereviews, bradfitz, josharian, rsc, adg
CC=golang-codereviews
https://golang.org/cl/141340043
2014-09-25 10:52:02 -07:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00