Skip to content

Commit 4999082

Browse files
committed
time: In the Time_Before method, cache the result of sec() calls.
The current implementation calls sec() for both the receiver t and the parameter u twice, if the seconds of both times are equal. This is the same optimization that has already been implemented in the Time_After method. This fixes no issue, as it is a trivial change.
1 parent 400d021 commit 4999082

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/time/time.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ func (t Time) Before(u Time) bool {
252252
if t.wall&u.wall&hasMonotonic != 0 {
253253
return t.ext < u.ext
254254
}
255-
return t.sec() < u.sec() || t.sec() == u.sec() && t.nsec() < u.nsec()
255+
ts := t.sec()
256+
us := u.sec()
257+
return ts < us || ts == us && t.nsec() < u.nsec()
256258
}
257259

258260
// Equal reports whether t and u represent the same time instant.

0 commit comments

Comments
 (0)