]> Cypherpunks repositories - gostls13.git/commitdiff
time: make time.Until a few nanoseconds faster
authorkorzhao <korzhao95@gmail.com>
Tue, 22 Aug 2023 06:22:53 +0000 (14:22 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 25 Aug 2023 15:10:18 +0000 (15:10 +0000)
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>

src/time/time.go

index cc9dd6652af41931b879cad20c54d6b61be35ac9..3d4416e76bf57b9d70c31bcd4f22edb89ee14603 100644 (file)
@@ -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