Skip to content

Commit

Permalink
[geneva] Tweak OtlpProtobufSerializer to access MetricPoint by ref (#…
Browse files Browse the repository at this point in the history
…2310)

Co-authored-by: Piotr Kiełkowicz <[email protected]>
  • Loading branch information
CodeBlanch and Kielek authored Nov 13, 2024
1 parent ea459ff commit afe4342
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

this.metricPointTagAndLengthIndex = cursor;
this.metricPointValueIndex = cursor + TagAndLengthSize;
foreach (var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
try
{
Expand All @@ -363,7 +363,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

var sum = metricPoint.GetSumLong();

this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, metricPoint, sum);
this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, in metricPoint, sum);

// Finish writing current batch
this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType);
Expand Down Expand Up @@ -394,7 +394,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

this.metricPointTagAndLengthIndex = cursor;
this.metricPointValueIndex = cursor + TagAndLengthSize;
foreach (var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
try
{
Expand All @@ -403,7 +403,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

var sum = metricPoint.GetSumDouble();

this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, metricPoint, sum);
this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Sum_data_points, in metricPoint, sum);

// Finish writing current batch
this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType);
Expand All @@ -427,7 +427,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

this.metricPointTagAndLengthIndex = cursor;
this.metricPointValueIndex = cursor + TagAndLengthSize;
foreach (var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
try
{
Expand All @@ -436,7 +436,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

var lastValue = metricPoint.GetGaugeLastValueLong();

this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, metricPoint, lastValue);
this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, in metricPoint, lastValue);

// Finish writing current batch
this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType);
Expand All @@ -460,7 +460,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

this.metricPointTagAndLengthIndex = cursor;
this.metricPointValueIndex = cursor + TagAndLengthSize;
foreach (var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
try
{
Expand All @@ -469,7 +469,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

var lastValue = metricPoint.GetGaugeLastValueDouble();

this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, metricPoint, lastValue);
this.WriteNumberDataPoint(buffer, ref cursor, FieldNumberConstants.Gauge_data_points, in metricPoint, lastValue);

// Finish writing current batch
this.WriteIndividualMessageTagsAndLength(buffer, ref cursor, metric.MetricType);
Expand All @@ -496,7 +496,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)

this.metricPointTagAndLengthIndex = cursor;
this.metricPointValueIndex = cursor + TagAndLengthSize;
foreach (var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
try
{
Expand Down Expand Up @@ -579,7 +579,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
this.metricPointTagAndLengthIndex = cursor;
this.metricPointValueIndex = cursor + TagAndLengthSize;

foreach (var metricPoint in metric.GetMetricPoints())
foreach (ref readonly var metricPoint in metric.GetMetricPoints())
{
try
{
Expand Down Expand Up @@ -664,7 +664,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
}
}

private void WriteNumberDataPoint<T>(byte[] buffer, ref int cursor, int fieldNumber, MetricPoint metricPoint, T value)
private void WriteNumberDataPoint<T>(byte[] buffer, ref int cursor, int fieldNumber, in MetricPoint metricPoint, T value)
{
if (typeof(T) == typeof(long))
{
Expand Down

0 comments on commit afe4342

Please sign in to comment.