Skip to content

Commit 8b04f33

Browse files
leecampbell-codeagentLeeCampbellclaude
authored
feat(#131): Fix build warnings from dotnet build Release configuration (#137)
* plan(#131): initial brief from issue * plan(#131): review brief * plan(#131): apply brief review feedback * plan(#131): review brief * plan(#131): apply brief review feedback * plan(#131): review brief * plan(#131): apply brief review feedback * plan(#131): review brief * plan(#131): create task breakdown * feat(#131): implement tasks * feat(#131): complete implementation * fix(#131): use char overload of StartsWith on net8.0 to resolve CA1865 Use preprocessor directive to select string.StartsWith(char) on net8.0 and string.StartsWith(string, StringComparison) on netstandard2.0, satisfying both CA1865 and CA1310 analyser rules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(#131): remove redundant HistogramIterationValue allocation in enumerator Current property now points directly to _currentIterationValue field, eliminating a dead allocation and the misleading indirection where MoveNext() reassigned Current to the same object that _currentIterationValue already referenced. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Lee Campbell <lee.ryan.campbell@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c300608 commit 8b04f33

13 files changed

Lines changed: 37 additions & 28 deletions

HdrHistogram/HistogramBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class HistogramBase : IRecorder
4747
private readonly int _bucketIndexOffset;
4848
private long _maxValue;
4949
private long _minNonZeroValue;
50-
private string _tag;
50+
private string? _tag;
5151

5252
/// <summary>
5353
/// An identifier for the Histogram. Maybe generated by the Recorder if used.
@@ -87,7 +87,7 @@ public abstract class HistogramBase : IRecorder
8787
/// <summary>
8888
/// Gets or Sets the optional Tag string associated with this histogram.
8989
/// </summary>
90-
public string Tag
90+
public string? Tag
9191
{
9292
get { return _tag; }
9393
set
@@ -704,7 +704,7 @@ private long ValueFromIndex(int index)
704704
return ValueFromIndex(bucketIndex, subBucketIndex);
705705
}
706706

707-
private IRecordedData GetData()
707+
private RecordedData GetData()
708708
{
709709
var relevantCounts = GetRelevantCounts();
710710
return new RecordedData(

HdrHistogram/HistogramEncoding.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static HistogramBase DecodeFromCompressedByteBuffer(ByteBuffer buffer, lo
6262
/// <param name="decompressor">The <see cref="DeflateStream"/> that is being used to decompress the payload. Optional.</param>
6363
/// <returns>The newly constructed histogram</returns>
6464
public static HistogramBase DecodeFromByteBuffer(ByteBuffer buffer, long minBarForHighestTrackableValue,
65-
DeflateStream decompressor = null)
65+
DeflateStream? decompressor = null)
6666
{
6767
var header = ReadHeader(buffer);
6868
var wordSizeInBytes = GetWordSizeInBytesFromCookie(header.Cookie);
@@ -165,7 +165,7 @@ private static HistogramBase Create(Type histogramType, IHeader header, long min
165165
}
166166
}
167167

168-
private static ByteBuffer PayLoadSourceBuffer(ByteBuffer buffer, DeflateStream decompressor, int expectedCapacity, IHeader header)
168+
private static ByteBuffer PayLoadSourceBuffer(ByteBuffer buffer, DeflateStream? decompressor, int expectedCapacity, IHeader header)
169169
{
170170
ByteBuffer payLoadSourceBuffer;
171171
if (decompressor == null)
@@ -239,7 +239,7 @@ private static Type GetBestTypeForWordSize(int wordSizeInBytes)
239239
case 8: return typeof(LongHistogram);
240240
case 9: return typeof(LongHistogram);
241241
default:
242-
throw new IndexOutOfRangeException();
242+
throw new InvalidOperationException($"Unexpected word size: {wordSizeInBytes}");
243243
}
244244
}
245245
}

HdrHistogram/HistogramFactoryDelegate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace HdrHistogram
1515
/// The number of significant decimal digits to which the histogram will maintain value resolution and separation.
1616
/// Must be a non-negative integer between 0 and 5.
1717
/// </param>
18+
#pragma warning disable CA1711
1819
public delegate HistogramBase HistogramFactoryDelegate(
1920
long instanceId, long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits);
21+
#pragma warning restore CA1711
2022
}

HdrHistogram/HistogramLogReader.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using HdrHistogram.Utilities;
22
using System;
33
using System.Collections.Generic;
4+
using System.Globalization;
45
using System.IO;
56
using System.Linq;
67
using System.Text.RegularExpressions;
@@ -239,31 +240,35 @@ private IEnumerable<string> ReadLines()
239240

240241
private static bool IsComment(string line)
241242
{
242-
return line.StartsWith("#");
243+
#if NETSTANDARD2_0
244+
return line.StartsWith("#", StringComparison.Ordinal);
245+
#else
246+
return line.StartsWith('#');
247+
#endif
243248
}
244249

245250
private static bool IsStartTime(string line)
246251
{
247-
return line.StartsWith("#[StartTime: ");
252+
return line.StartsWith("#[StartTime: ", StringComparison.Ordinal);
248253
}
249254

250255
private static bool IsBaseTime(string line)
251256
{
252-
return line.StartsWith("#[BaseTime: ");
257+
return line.StartsWith("#[BaseTime: ", StringComparison.Ordinal);
253258
}
254259

255260
private static bool IsLegend(string line)
256261
{
257262
var legend = "\"StartTimestamp\",\"Interval_Length\",\"Interval_Max\",\"Interval_Compressed_Histogram\"";
258-
return line.Equals(legend);
263+
return string.Equals(line, legend, StringComparison.Ordinal);
259264
}
260265
private static bool IsV1Legend(string line)
261266
{
262267
var legend = "\"StartTimestamp\",\"EndTimestamp\",\"Interval_Max\",\"Interval_Compressed_Histogram\"";
263-
return line.Equals(legend);
268+
return string.Equals(line, legend, StringComparison.Ordinal);
264269
}
265270

266-
private static string ParseTag(string value)
271+
private static string? ParseTag(string value)
267272
{
268273
if (string.IsNullOrWhiteSpace(value))
269274
return null;
@@ -288,7 +293,7 @@ private static double ParseBaseTime(string line)
288293
private static double ParseDouble(Match match, string group)
289294
{
290295
var value = match.Groups[group].Value;
291-
return double.Parse(value);
296+
return double.Parse(value, CultureInfo.InvariantCulture);
292297
}
293298

294299
/// <summary>

HdrHistogram/HistogramLogWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public sealed class HistogramLogWriter : IDisposable
1414
private const string HistogramLogFormatVersion = "1.3";
1515

1616
private readonly TextWriter _log;
17-
private bool _hasHeaderWritten = false;
18-
private int _isDisposed = 0;
17+
private bool _hasHeaderWritten;
18+
private int _isDisposed;
1919

2020
/// <summary>
2121
/// Writes the provided histograms to the underlying <see cref="Stream"/> with a given overall start time.

HdrHistogram/IntConcurrentHistogram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class IntConcurrentHistogram : HistogramBase
2121
{
2222
private readonly WriterReaderPhaser _wrp = new WriterReaderPhaser();
2323
private readonly AtomicIntArray _counts;
24-
private long _totalCount = 0L;
24+
private long _totalCount;
2525

2626
/// <summary>
2727
/// Construct a <see cref="IntConcurrentHistogram"/> given the lowest and highest values to be tracked and a number of significant decimal digits.

HdrHistogram/Iteration/AbstractHistogramEnumerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal abstract class AbstractHistogramEnumerator : IEnumerator<HistogramItera
3535
protected long TotalCountToCurrentIndex { get; private set; }
3636
protected long CountAtThisValue { get; private set; }
3737

38-
public HistogramIterationValue Current { get; private set; }
38+
public HistogramIterationValue Current => _currentIterationValue;
3939

4040
protected AbstractHistogramEnumerator(HistogramBase histogram)
4141
{
@@ -160,7 +160,7 @@ bool IEnumerator.MoveNext()
160160
var canMove = HasNext();
161161
if (canMove)
162162
{
163-
Current = Next();
163+
Next();
164164
}
165165
return canMove;
166166
}

HdrHistogram/LongConcurrentHistogram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class LongConcurrentHistogram : HistogramBase
2121
{
2222
private readonly WriterReaderPhaser _wrp = new WriterReaderPhaser();
2323
private readonly AtomicLongArray _counts;
24-
private long _totalCount = 0L;
24+
private long _totalCount;
2525

2626

2727
/// <summary>

HdrHistogram/Persistence/CountsDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace HdrHistogram.Persistence
88
/// </summary>
99
public static class CountsDecoder
1010
{
11-
private static readonly IDictionary<int, ICountsDecoder> Decoders;
11+
private static readonly Dictionary<int, ICountsDecoder> Decoders;
1212

1313
static CountsDecoder()
1414
{

HdrHistogram/Recorder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Recorder : IRecorder
3030
private readonly HistogramFactoryDelegate _histogramFactory;
3131

3232
private HistogramBase _activeHistogram;
33-
private HistogramBase _inactiveHistogram;
33+
private HistogramBase? _inactiveHistogram;
3434

3535
/// <summary>
3636
/// Creates a recorder that will delegate recording to histograms created from these parameters.
@@ -147,7 +147,7 @@ public HistogramBase GetIntervalHistogram()
147147
/// NOTE: The caller is responsible for not recycling the same returned interval histogram more than once.
148148
/// If the same interval histogram instance is recycled more than once, behavior is undefined.
149149
/// </remarks>
150-
public HistogramBase GetIntervalHistogram(HistogramBase histogramToRecycle)
150+
public HistogramBase GetIntervalHistogram(HistogramBase? histogramToRecycle)
151151
{
152152
lock (_gate)
153153
{
@@ -157,7 +157,7 @@ public HistogramBase GetIntervalHistogram(HistogramBase histogramToRecycle)
157157
PerformIntervalSample();
158158
var sampledHistogram = _inactiveHistogram;
159159
_inactiveHistogram = null; // Once we expose the sample, we can't reuse it internally until it is recycled
160-
return sampledHistogram;
160+
return sampledHistogram!;
161161
}
162162
}
163163

@@ -172,7 +172,7 @@ public void GetIntervalHistogramInto(HistogramBase targetHistogram)
172172
lock (_gate)
173173
{
174174
PerformIntervalSample();
175-
_inactiveHistogram.CopyInto(targetHistogram);
175+
_inactiveHistogram!.CopyInto(targetHistogram);
176176
}
177177
}
178178

@@ -227,7 +227,7 @@ private void PerformIntervalSample()
227227
}
228228
}
229229

230-
private void ValidateFitAsReplacementHistogram(HistogramBase replacementHistogram)
230+
private void ValidateFitAsReplacementHistogram(HistogramBase? replacementHistogram)
231231
{
232232
if (replacementHistogram != null && replacementHistogram.InstanceId != _activeHistogram.InstanceId)
233233
{

0 commit comments

Comments
 (0)