Skip to content

Commit 9d7350c

Browse files
alinasmirnovaAndreyAkinshin
authored andcommitted
Fixed warnings on null assignments
1 parent 7fbbc9f commit 9d7350c

File tree

24 files changed

+39
-40
lines changed

24 files changed

+39
-40
lines changed

src/BenchmarkDotNet.Diagnostics.Windows/InliningDiagnoser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class InliningDiagnoser : JitDiagnoser<object>, IProfiler
1313

1414
private readonly bool logFailuresOnly = true;
1515
private readonly bool filterByNamespace = true;
16-
private readonly string[] allowedNamespaces = null;
16+
private readonly string[]? allowedNamespaces = null;
1717
private string defaultNamespace;
1818

1919
// ReSharper disable once EmptyConstructor parameterless ctor is mandatory for DiagnosersLoader.CreateDiagnoser

src/BenchmarkDotNet.Diagnostics.Windows/Tracing/NativeMemoryLogParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private IEnumerable<Metric> Parse(TraceLog traceLog)
9595
var heapParser = new HeapTraceProviderTraceEventParser(eventSource);
9696
// We index by heap address and then within the heap we remember the allocation stack
9797
var heaps = new Dictionary<Address, Dictionary<Address, long>>();
98-
Dictionary<Address, long> lastHeapAllocs = null;
98+
Dictionary<Address, long>? lastHeapAllocs = null;
9999

100100
Address lastHeapHandle = 0;
101101

src/BenchmarkDotNet.Disassembler.x64/SourceCodeProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static SourceLocation FindNearestLine(PdbFunction function, int ilOffset
134134
return null;
135135

136136
int distance = int.MaxValue;
137-
SourceLocation nearest = null;
137+
SourceLocation? nearest = null;
138138

139139
foreach (PdbSequencePointCollection sequenceCollection in function.SequencePoints)
140140
{
@@ -183,7 +183,7 @@ private static PdbReader GetReaderForMethod(ClrMethod method)
183183
ClrModule module = method?.Type?.Module;
184184
PdbInfo info = module?.Pdb;
185185

186-
PdbReader reader = null;
186+
PdbReader? reader = null;
187187
if (info != null)
188188
{
189189
if (!s_pdbReaders.TryGetValue(info, out reader))

src/BenchmarkDotNet/Characteristics/Characteristic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected Characteristic(
8686

8787
private object FallbackValue { get; }
8888

89-
public object this[CharacteristicObject obj]
89+
public object? this[CharacteristicObject obj]
9090
{
9191
get { return obj.GetValue(this); }
9292
set { obj.SetValue(this, value); }

src/BenchmarkDotNet/Disassemblers/MonoDisassembler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static DisassemblyResult CreateErrorResult(IReadOnlyList<string?> input,
128128
//line example 2: 0000000000000000 subq $0x28, %rsp
129129
private static readonly Regex InstructionRegex = new Regex(@"\s*(?<address>[0-9a-f]+)(\:\s+([0-9a-f]{2}\s+)+)?\s+(?<instruction>.*)\s*", RegexOptions.Compiled);
130130

131-
private static bool TryParseInstruction(string line, out MonoCode instruction)
131+
private static bool TryParseInstruction(string line, out MonoCode? instruction)
132132
{
133133
instruction = null;
134134
var match = InstructionRegex.Match(line);

src/BenchmarkDotNet/Disassemblers/SourceCodeProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private static ManagedSymbolModule GetReaderForMethod(ClrMethod method)
150150
ClrModule module = method?.Type?.Module;
151151
PdbInfo info = module?.Pdb;
152152

153-
ManagedSymbolModule reader = null;
153+
ManagedSymbolModule? reader = null;
154154
if (info != null)
155155
{
156156
if (!s_pdbReaders.TryGetValue(info, out reader))

src/BenchmarkDotNet/Engines/AnonymousPipesHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void SendSignal(HostSignal hostSignal)
6363
public void ReportResults(RunResults runResults) => runResults.Print(outWriter);
6464

6565
[PublicAPI] // called from generated code
66-
public static bool TryGetFileHandles(string[] args, out string writeHandle, out string readHandle)
66+
public static bool TryGetFileHandles(string[] args, out string? writeHandle, out string? readHandle)
6767
{
6868
for (int i = 0; i < args.Length; i++)
6969
{

src/BenchmarkDotNet/Engines/Consumer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static readonly HashSet<Type> SupportedTypes
3131
private double doubleHolder;
3232
private long longHolder;
3333
private ulong ulongHolder;
34-
private volatile object objectHolder;
34+
private volatile object? objectHolder;
3535
private volatile IntPtr ptrHolder;
3636
private volatile UIntPtr uptrHolder;
3737
#pragma warning restore IDE0052 // Remove unread private members
@@ -157,7 +157,7 @@ public void Consume<T>(in T value)
157157
internal static bool IsConsumable(Type type)
158158
=> SupportedTypes.Contains(type) || type.GetTypeInfo().IsClass || type.GetTypeInfo().IsInterface;
159159

160-
internal static bool HasConsumableField(Type type, out FieldInfo consumableField)
160+
internal static bool HasConsumableField(Type type, out FieldInfo? consumableField)
161161
{
162162
var typeInfo = type.GetTypeInfo();
163163

src/BenchmarkDotNet/Environments/ProcessorBrandStringHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static string GetBrandStyledActualFrequency(Frequency? frequency)
9494
{
9595
var data = ResourceHelper.LoadResource("BenchmarkDotNet.Environments.microarchitectures.txt").Split('\r', '\n');
9696
var dictionary = new Dictionary<string, string>();
97-
string currentMicroarchitecture = null;
97+
string? currentMicroarchitecture = null;
9898
foreach (string line in data)
9999
{
100100
if (line.StartsWith("//") || string.IsNullOrWhiteSpace(line))

src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal static CoreRuntime FromVersion(Version version)
7777
}
7878
}
7979

80-
internal static bool TryGetVersion(out Version version)
80+
internal static bool TryGetVersion(out Version? version)
8181
{
8282
// we can't just use System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription
8383
// because it can be null and it reports versions like 4.6.* for .NET Core 2.*
@@ -124,7 +124,7 @@ internal static bool TryGetVersion(out Version version)
124124
// sample input:
125125
// for dotnet run: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.12\
126126
// for dotnet publish: C:\Users\adsitnik\source\repos\ConsoleApp25\ConsoleApp25\bin\Release\netcoreapp2.0\win-x64\publish\
127-
internal static bool TryGetVersionFromRuntimeDirectory(string runtimeDirectory, out Version version)
127+
internal static bool TryGetVersionFromRuntimeDirectory(string runtimeDirectory, out Version? version)
128128
{
129129
if (!string.IsNullOrEmpty(runtimeDirectory) && Version.TryParse(GetParsableVersionPart(new DirectoryInfo(runtimeDirectory).Name), out version))
130130
{
@@ -141,7 +141,7 @@ internal static bool TryGetVersionFromRuntimeDirectory(string runtimeDirectory,
141141
// 2.2: 4.6.27817.03 @BuiltBy: dlab14-DDVSOWINAGE101 @Branch: release/2.2 @SrcCode: https://github.com/dotnet/coreclr/tree/ce1d090d33b400a25620c0145046471495067cc7, Microsoft .NET Framework
142142
// 3.0: 3.0.0-preview8.19379.2+ac25be694a5385a6a1496db40de932df0689b742, Microsoft .NET Core
143143
// 5.0: 5.0.0-alpha1.19413.7+0ecefa44c9d66adb8a997d5778dc6c246ad393a7, Microsoft .NET Core
144-
internal static bool TryGetVersionFromProductInfo(string productVersion, string productName, out Version version)
144+
internal static bool TryGetVersionFromProductInfo(string productVersion, string productName, out Version? version)
145145
{
146146
if (!string.IsNullOrEmpty(productVersion) && !string.IsNullOrEmpty(productName))
147147
{
@@ -175,7 +175,7 @@ internal static bool TryGetVersionFromProductInfo(string productVersion, string
175175
// sample input:
176176
// .NETCoreApp,Version=v2.0
177177
// .NETCoreApp,Version=v2.1
178-
internal static bool TryGetVersionFromFrameworkName(string frameworkName, out Version version)
178+
internal static bool TryGetVersionFromFrameworkName(string frameworkName, out Version? version)
179179
{
180180
const string versionPrefix = ".NETCoreApp,Version=v";
181181
if (!string.IsNullOrEmpty(frameworkName) && frameworkName.StartsWith(versionPrefix))

0 commit comments

Comments
 (0)