From: korzhao Date: Tue, 22 Aug 2023 06:22:53 +0000 (+0800) Subject: time: make time.Until a few nanoseconds faster X-Git-Tag: go1.22rc1~1095 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=882a356ec020919b733bf66d6bcb775fe7a92bad;p=gostls13.git 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 Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- 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