diff options
| author | korzhao <korzhao95@gmail.com> | 2023-08-22 14:22:53 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-08-25 15:10:18 +0000 |
| commit | 882a356ec020919b733bf66d6bcb775fe7a92bad (patch) | |
| tree | 66bf359e402c15f87b74401cd54927b61e77db34 /src | |
| parent | 890a62bf1b8022833d3cb616d3d7911b7f1d289a (diff) | |
| download | go-882a356ec020919b733bf66d6bcb775fe7a92bad.tar.xz | |
time: make time.Until a few nanoseconds faster
This is similar to CL 518336.
For #61765.
Change-Id: I7c1d92a3b3e2b6c1c0058a2094997d93082ad139
Reviewed-on: https://go-review.googlesource.com/c/go/+/521237
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/time/time.go | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/time/time.go b/src/time/time.go index cc9dd6652a..3d4416e76b 100644 --- a/src/time/time.go +++ b/src/time/time.go @@ -939,14 +939,11 @@ func Since(t Time) Duration { // Until returns the duration until t. // It is shorthand for t.Sub(time.Now()). func Until(t Time) Duration { - var now Time if t.wall&hasMonotonic != 0 { // Common case optimization: if t has monotonic time, then Sub will use only it. - now = Time{hasMonotonic, runtimeNano() - startNano, nil} - } else { - now = Now() + return subMono(t.ext, runtimeNano()-startNano) } - return t.Sub(now) + return t.Sub(Now()) } // AddDate returns the time corresponding to adding the |
