@@ -354,7 +354,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
354354
355355                    this . metricPointTagAndLengthIndex  =  cursor ; 
356356                    this . metricPointValueIndex  =  cursor  +  TagAndLengthSize ; 
357-                     foreach  ( var  metricPoint  in  metric . GetMetricPoints ( ) ) 
357+                     foreach  ( ref  readonly  var  metricPoint  in  metric . GetMetricPoints ( ) ) 
358358                    { 
359359                        try 
360360                        { 
@@ -363,7 +363,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
363363
364364                            var  sum  =  metricPoint . GetSumLong ( ) ; 
365365
366-                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Sum_data_points ,  metricPoint ,  sum ) ; 
366+                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Sum_data_points ,  in   metricPoint ,  sum ) ; 
367367
368368                            // Finish writing current batch 
369369                            this . WriteIndividualMessageTagsAndLength ( buffer ,  ref  cursor ,  metric . MetricType ) ; 
@@ -394,7 +394,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
394394
395395                    this . metricPointTagAndLengthIndex  =  cursor ; 
396396                    this . metricPointValueIndex  =  cursor  +  TagAndLengthSize ; 
397-                     foreach  ( var  metricPoint  in  metric . GetMetricPoints ( ) ) 
397+                     foreach  ( ref  readonly  var  metricPoint  in  metric . GetMetricPoints ( ) ) 
398398                    { 
399399                        try 
400400                        { 
@@ -403,7 +403,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
403403
404404                            var  sum  =  metricPoint . GetSumDouble ( ) ; 
405405
406-                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Sum_data_points ,  metricPoint ,  sum ) ; 
406+                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Sum_data_points ,  in   metricPoint ,  sum ) ; 
407407
408408                            // Finish writing current batch 
409409                            this . WriteIndividualMessageTagsAndLength ( buffer ,  ref  cursor ,  metric . MetricType ) ; 
@@ -427,7 +427,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
427427
428428                    this . metricPointTagAndLengthIndex  =  cursor ; 
429429                    this . metricPointValueIndex  =  cursor  +  TagAndLengthSize ; 
430-                     foreach  ( var  metricPoint  in  metric . GetMetricPoints ( ) ) 
430+                     foreach  ( ref  readonly  var  metricPoint  in  metric . GetMetricPoints ( ) ) 
431431                    { 
432432                        try 
433433                        { 
@@ -436,7 +436,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
436436
437437                            var  lastValue  =  metricPoint . GetGaugeLastValueLong ( ) ; 
438438
439-                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Gauge_data_points ,  metricPoint ,  lastValue ) ; 
439+                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Gauge_data_points ,  in   metricPoint ,  lastValue ) ; 
440440
441441                            // Finish writing current batch 
442442                            this . WriteIndividualMessageTagsAndLength ( buffer ,  ref  cursor ,  metric . MetricType ) ; 
@@ -460,7 +460,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
460460
461461                    this . metricPointTagAndLengthIndex  =  cursor ; 
462462                    this . metricPointValueIndex  =  cursor  +  TagAndLengthSize ; 
463-                     foreach  ( var  metricPoint  in  metric . GetMetricPoints ( ) ) 
463+                     foreach  ( ref  readonly  var  metricPoint  in  metric . GetMetricPoints ( ) ) 
464464                    { 
465465                        try 
466466                        { 
@@ -469,7 +469,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
469469
470470                            var  lastValue  =  metricPoint . GetGaugeLastValueDouble ( ) ; 
471471
472-                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Gauge_data_points ,  metricPoint ,  lastValue ) ; 
472+                             this . WriteNumberDataPoint ( buffer ,  ref  cursor ,  FieldNumberConstants . Gauge_data_points ,  in   metricPoint ,  lastValue ) ; 
473473
474474                            // Finish writing current batch 
475475                            this . WriteIndividualMessageTagsAndLength ( buffer ,  ref  cursor ,  metric . MetricType ) ; 
@@ -496,7 +496,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
496496
497497                    this . metricPointTagAndLengthIndex  =  cursor ; 
498498                    this . metricPointValueIndex  =  cursor  +  TagAndLengthSize ; 
499-                     foreach  ( var  metricPoint  in  metric . GetMetricPoints ( ) ) 
499+                     foreach  ( ref  readonly  var  metricPoint  in  metric . GetMetricPoints ( ) ) 
500500                    { 
501501                        try 
502502                        { 
@@ -579,7 +579,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
579579                    this . metricPointTagAndLengthIndex  =  cursor ; 
580580                    this . metricPointValueIndex  =  cursor  +  TagAndLengthSize ; 
581581
582-                     foreach  ( var  metricPoint  in  metric . GetMetricPoints ( ) ) 
582+                     foreach  ( ref  readonly  var  metricPoint  in  metric . GetMetricPoints ( ) ) 
583583                    { 
584584                        try 
585585                        { 
@@ -664,7 +664,7 @@ private void SerializeMetric(byte[] buffer, ref int cursor, Metric metric)
664664        } 
665665    } 
666666
667-     private  void  WriteNumberDataPoint < T > ( byte [ ]  buffer ,  ref  int  cursor ,  int  fieldNumber ,  MetricPoint  metricPoint ,  T  value ) 
667+     private  void  WriteNumberDataPoint < T > ( byte [ ]  buffer ,  ref  int  cursor ,  int  fieldNumber ,  in   MetricPoint  metricPoint ,  T  value ) 
668668    { 
669669        if  ( typeof ( T )  ==  typeof ( long ) ) 
670670        { 
0 commit comments