From: Rob Pike Date: Wed, 22 Aug 2012 21:36:23 +0000 (-0700) Subject: time: avoid data race in abs X-Git-Tag: go1.1rc2~2608 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=84a5a9b558fbe1a4d20d1be822eefa1fd504d8df;p=gostls13.git time: avoid data race in abs Fixes #3967. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6460115 --- diff --git a/src/pkg/time/time.go b/src/pkg/time/time.go index f898284621..ef966c3ef0 100644 --- a/src/pkg/time/time.go +++ b/src/pkg/time/time.go @@ -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 {