Skip to content

Commit

Permalink
Use big.Rat#Sign() and drop a global var
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Nov 19, 2019
1 parent b35a5ef commit c04436f
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions lib/executor/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,14 @@ func getScaledArrivalRate(es *lib.ExecutionSegment, rate int64, period time.Dura
return es.InPlaceScaleRat(big.NewRat(rate, int64(period)))
}

// just a cached value to avoid allocating it every getTickerPeriod() call
var zero = big.NewInt(0) //nolint:gochecknoglobals

// getTickerPeriod is just a helper function that returns the ticker interval
// we need for given arrival-rate parameters.
//
// It's possible for this function to return a zero duration (i.e. valid=false)
// and 0 isn't a valid ticker period. This happens so we don't divide by 0 when
// the arrival-rate period is 0. This case has to be handled separately.
func getTickerPeriod(scaledArrivalRate *big.Rat) types.NullDuration {
if scaledArrivalRate.Num().Cmp(zero) == 0 {
if scaledArrivalRate.Sign() == 0 {
return types.NewNullDuration(0, false)
}
// Basically, the ticker rate is time.Duration(1/arrivalRate). Considering
Expand Down

0 comments on commit c04436f

Please sign in to comment.