aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/time/time.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2015-01-15 00:27:56 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-01-15 00:27:56 +0000
commitf8d9fa9e80b57f89e7877ce6cad8a3464879009b (patch)
tree58a1724fee16d2b03c65678c4dd9b50bb97137a9 /libgo/go/time/time.go
parent6bd3f109d8d8fa58eeccd6b3504721b4f20c00c2 (diff)
downloadgcc-f8d9fa9e80b57f89e7877ce6cad8a3464879009b.zip
gcc-f8d9fa9e80b57f89e7877ce6cad8a3464879009b.tar.gz
gcc-f8d9fa9e80b57f89e7877ce6cad8a3464879009b.tar.bz2
libgo, compiler: Upgrade libgo to Go 1.4, except for runtime.
This upgrades all of libgo other than the runtime package to the Go 1.4 release. In Go 1.4 much of the runtime was rewritten into Go. Merging that code will take more time and will not change the API, so I'm putting it off for now. There are a few runtime changes anyhow, to accomodate other packages that rely on minor modifications to the runtime support. The compiler changes slightly to add a one-bit flag to each type descriptor kind that is stored directly in an interface, which for gccgo is currently only pointer types. Another one-bit flag (gcprog) is reserved because it is used by the gc compiler, but gccgo does not currently use it. There is another error check in the compiler since I ran across it during testing. gotools/: * Makefile.am (go_cmd_go_files): Sort entries. Add generate.go. * Makefile.in: Rebuild. From-SVN: r219627
Diffstat (limited to 'libgo/go/time/time.go')
-rw-r--r--libgo/go/time/time.go43
1 files changed, 20 insertions, 23 deletions
diff --git a/libgo/go/time/time.go b/libgo/go/time/time.go
index 0a2b091..0300e84 100644
--- a/libgo/go/time/time.go
+++ b/libgo/go/time/time.go
@@ -31,6 +31,11 @@ import "errors"
// change the instant in time being denoted and therefore does not affect the
// computations described in earlier paragraphs.
//
+// Note that the Go == operator compares not just the time instant but also the
+// Location. Therefore, Time values should not be used as map or database keys
+// without first guaranteeing that the identical Location has been set for all
+// values, which can be achieved through use of the UTC or Local method.
+//
type Time struct {
// sec gives the number of seconds elapsed since
// January 1, year 1 00:00:00 UTC.
@@ -39,14 +44,7 @@ type Time struct {
// nsec specifies a non-negative nanosecond
// offset within the second named by Seconds.
// It must be in the range [0, 999999999].
- //
- // It is declared as uintptr instead of int32 or uint32
- // to avoid garbage collector aliasing in the case where
- // on a 64-bit system the int32 or uint32 field is written
- // over the low half of a pointer, creating another pointer.
- // TODO(rsc): When the garbage collector is completely
- // precise, change back to int32.
- nsec uintptr
+ nsec int32
// loc specifies the Location that should be used to
// determine the minute, hour, month, day, and year
@@ -475,29 +473,28 @@ func (d Duration) String() string {
if u < uint64(Second) {
// Special case: if duration is smaller than a second,
// use smaller units, like 1.2ms
- var (
- prec int
- unit byte
- )
+ var prec int
+ w--
+ buf[w] = 's'
+ w--
switch {
case u == 0:
return "0"
case u < uint64(Microsecond):
// print nanoseconds
prec = 0
- unit = 'n'
+ buf[w] = 'n'
case u < uint64(Millisecond):
// print microseconds
prec = 3
- unit = 'u'
+ // U+00B5 'µ' micro sign == 0xC2 0xB5
+ w-- // Need room for two bytes.
+ copy(buf[w:], "µ")
default:
// print milliseconds
prec = 6
- unit = 'm'
+ buf[w] = 'm'
}
- w -= 2
- buf[w] = unit
- buf[w+1] = 's'
w, u = fmtFrac(buf[:w], u, prec)
w = fmtInt(buf[:w], u)
} else {
@@ -620,7 +617,7 @@ func (t Time) Add(d Duration) Time {
t.sec--
nsec += 1e9
}
- t.nsec = uintptr(nsec)
+ t.nsec = nsec
return t
}
@@ -783,7 +780,7 @@ func now() (sec int64, nsec int32)
// Now returns the current local time.
func Now() Time {
sec, nsec := now()
- return Time{sec + unixToInternal, uintptr(nsec), Local}
+ return Time{sec + unixToInternal, nsec, Local}
}
// UTC returns t with the location set to UTC.
@@ -900,7 +897,7 @@ func (t *Time) UnmarshalBinary(data []byte) error {
int64(buf[3])<<32 | int64(buf[2])<<40 | int64(buf[1])<<48 | int64(buf[0])<<56
buf = buf[8:]
- t.nsec = uintptr(int32(buf[3]) | int32(buf[2])<<8 | int32(buf[1])<<16 | int32(buf[0])<<24)
+ t.nsec = int32(buf[3]) | int32(buf[2])<<8 | int32(buf[1])<<16 | int32(buf[0])<<24
buf = buf[4:]
offset := int(int16(buf[1])|int16(buf[0])<<8) * 60
@@ -979,7 +976,7 @@ func Unix(sec int64, nsec int64) Time {
sec--
}
}
- return Time{sec + unixToInternal, uintptr(nsec), Local}
+ return Time{sec + unixToInternal, int32(nsec), Local}
}
func isLeap(year int) bool {
@@ -1088,7 +1085,7 @@ func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) T
unix -= int64(offset)
}
- return Time{unix + unixToInternal, uintptr(nsec), loc}
+ return Time{unix + unixToInternal, int32(nsec), loc}
}
// Truncate returns the result of rounding t down to a multiple of d (since the zero time).