Skip to content

Commit

Permalink
replace pow util function with bit operation
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinForReal committed Jun 2, 2023
1 parent cc8963d commit 5f3713a
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions sdk/azcore/runtime/policy_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ func setDefaults(o *policy.RetryOptions) {
}

func calcDelay(o policy.RetryOptions, try int32) time.Duration { // try is >=1; never 0
pow := func(number int64, exponent int32) int64 { // pow is nested helper function
var result int64 = 1
for n := int32(0); n < exponent; n++ {
result *= number
}
return result
}

delay := time.Duration(pow(2, try)-1) * o.RetryDelay
delay := time.Duration((1<<try)-1) * o.RetryDelay

// Introduce some jitter: [0.0, 1.0) / 2 = [0.0, 0.5) + 0.8 = [0.8, 1.3)
delay = time.Duration(delay.Seconds() * (rand.Float64()/2 + 0.8) * float64(time.Second)) // NOTE: We want math/rand; not crypto/rand
Expand Down

0 comments on commit 5f3713a

Please sign in to comment.