Skip to content

Commit

Permalink
Minor optimization for HistogramBuckets enumeration (#2668)
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla authored Nov 23, 2021
1 parent fb161af commit e7f026e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/OpenTelemetry/Metrics/HistogramBuckets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ internal HistogramBuckets(double[] histogramBounds)
public struct Enumerator
{
private readonly int numberOfBuckets;
private readonly int numberofExplicitBounds;
private readonly HistogramBuckets histogramMeasurements;
private int index;

Expand All @@ -56,8 +55,7 @@ internal Enumerator(HistogramBuckets histogramMeasurements)
this.histogramMeasurements = histogramMeasurements;
this.index = 0;
this.Current = default;
this.numberOfBuckets = histogramMeasurements.ExplicitBounds == null ? 0 : histogramMeasurements.BucketCounts.Length;
this.numberofExplicitBounds = histogramMeasurements.ExplicitBounds == null ? 0 : histogramMeasurements.ExplicitBounds.Length;
this.numberOfBuckets = histogramMeasurements.AggregatedBucketCounts == null ? 0 : histogramMeasurements.AggregatedBucketCounts.Length;
}

public HistogramBucket Current { get; private set; }
Expand All @@ -66,7 +64,7 @@ public bool MoveNext()
{
if (this.index < this.numberOfBuckets)
{
double explicitBound = this.index < this.numberofExplicitBounds
double explicitBound = this.index < this.numberOfBuckets - 1
? this.histogramMeasurements.ExplicitBounds[this.index]
: double.PositiveInfinity;
long bucketCount = this.histogramMeasurements.AggregatedBucketCounts[this.index];
Expand Down

0 comments on commit e7f026e

Please sign in to comment.