From 882a356ec020919b733bf66d6bcb775fe7a92bad Mon Sep 17 00:00:00 2001 From: korzhao Date: Tue, 22 Aug 2023 14:22:53 +0800 Subject: [PATCH] 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 --- src/time/time.go | 7 ++----- 1 file 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 -- 2.50.0