aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2012-09-22 05:54:44 +1000
committerRob Pike <r@golang.org>2012-09-22 05:54:44 +1000
commit01b381f33701d8bdc773fedabc12574db00113e1 (patch)
treead1309662ca0473b2bf0c0a9bf35dfba5fdf7609
parent2d514df3b380d10cd53deac02fd67a599c37e652 (diff)
downloadgo-01b381f33701d8bdc773fedabc12574db00113e1.tar.gz
go-01b381f33701d8bdc773fedabc12574db00113e1.zip
[release-branch.go1] time: avoid data race in abs
««« backport b2855a1654b6 time: avoid data race in abs Fixes #3967. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6460115 »»»
-rw-r--r--src/pkg/time/time.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/pkg/time/time.go b/src/pkg/time/time.go
index 2461dac06f..d48ca0c269 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 {