Skip to content

Commit

Permalink
time: In the Time_Before method, cache the result of sec() calls.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skaldesh committed Aug 28, 2019
1 parent 400d021 commit 4999082
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ func (t Time) Before(u Time) bool {
if t.wall&u.wall&hasMonotonic != 0 {
return t.ext < u.ext
}
return t.sec() < u.sec() || t.sec() == u.sec() && t.nsec() < u.nsec()
ts := t.sec()
us := u.sec()
return ts < us || ts == us && t.nsec() < u.nsec()
}

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

0 comments on commit 4999082

Please sign in to comment.