time: avoid data race in abs

Fixes #3967.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6460115
This commit is contained in:
Rob Pike 2012-08-22 14:36:23 -07:00
parent 2eb6a16e16
commit 84a5a9b558

View file

@ -241,10 +241,10 @@ func (t Time) IsZero() bool {
// It is called when computing a presentation property like Month or Hour.
func (t Time) abs() uint64 {
l := t.loc
if l == nil {
l = &utcLoc
// Avoid function calls when possible.
if l == nil || l == &localLoc {
l = l.get()
}
// Avoid function call if we hit the local time cache.
sec := t.sec + internalToUnix
if l != &utcLoc {
if l.cacheZone != nil && l.cacheStart <= sec && sec < l.cacheEnd {