Skip to content

Commit a092803

Browse files
authored
chore: Replace string.IsNullOrEmpty method to IsBlank/IsNotBlank extension methods (#2908)
* chore: replace string.IsNullOrEmpty to IsBlank/IsNotBlank extension methods * chore: reflect review comments
1 parent 35e75f7 commit a092803

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+107
-84
lines changed

src/BenchmarkDotNet/Characteristics/CharacteristicObject.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics.CodeAnalysis;
44
using System.Linq;
55
using System.Reflection;
6+
using BenchmarkDotNet.Extensions;
67
using JetBrains.Annotations;
78

89
#nullable enable
@@ -21,8 +22,8 @@ public abstract class CharacteristicObject
2122

2223
protected static string ResolveId(CharacteristicObject obj, string? actual)
2324
{
24-
if (!string.IsNullOrEmpty(actual) && actual != IdCharacteristic.FallbackValue)
25-
return actual!;
25+
if (actual.IsNotBlank() && actual != IdCharacteristic.FallbackValue)
26+
return actual;
2627

2728
string result = CharacteristicSetPresenter.Display.ToPresentation(obj);
2829

@@ -48,7 +49,7 @@ protected CharacteristicObject()
4849

4950
protected CharacteristicObject(string id) : this()
5051
{
51-
if (!string.IsNullOrEmpty(id))
52+
if (id.IsNotBlank())
5253
{
5354
IdCharacteristic[this] = id;
5455
}

src/BenchmarkDotNet/Code/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ internal static string Generate(BuildPartition buildPartition)
8888

8989
private static void AddNonEmptyUnique(HashSet<string> items, string value)
9090
{
91-
if (!string.IsNullOrEmpty(value))
91+
if (value.IsNotBlank())
9292
items.Add(value);
9393
}
9494

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private static Parser CreateParser(ILogger logger)
232232

233233
private static bool Validate(CommandLineOptions options, ILogger logger)
234234
{
235-
if (!AvailableJobs.ContainsKey(options.BaseJob))
235+
if (options.BaseJob.IsBlank() || !AvailableJobs.ContainsKey(options.BaseJob))
236236
{
237237
logger.WriteLineError($"The provided base job \"{options.BaseJob}\" is invalid. Available options are: {string.Join(", ", AvailableJobs.Keys)}.");
238238
return false;
@@ -310,7 +310,7 @@ private static bool Validate(CommandLineOptions options, ILogger logger)
310310
return false;
311311
}
312312

313-
if (!string.IsNullOrEmpty(options.StatisticalTestThreshold) && !Threshold.TryParse(options.StatisticalTestThreshold, out _))
313+
if (options.StatisticalTestThreshold.IsNotBlank() && !Threshold.TryParse(options.StatisticalTestThreshold, out _))
314314
{
315315
logger.WriteLineError("Invalid Threshold for Statistical Test. Use --help to see examples.");
316316
return false;
@@ -325,7 +325,7 @@ private static bool Validate(CommandLineOptions options, ILogger logger)
325325
return true;
326326
}
327327

328-
private static IConfig CreateConfig(CommandLineOptions options, IConfig globalConfig, string[] args)
328+
private static IConfig CreateConfig(CommandLineOptions options, IConfig? globalConfig, string[] args)
329329
{
330330
var config = new ManualConfig();
331331

@@ -354,12 +354,12 @@ private static IConfig CreateConfig(CommandLineOptions options, IConfig globalCo
354354
maxDepth: options.DisassemblerRecursiveDepth,
355355
filters: options.DisassemblerFilters.ToArray(),
356356
exportDiff: options.DisassemblerDiff)));
357-
if (!string.IsNullOrEmpty(options.Profiler))
357+
if (options.Profiler.IsNotBlank())
358358
config.AddDiagnoser(DiagnosersLoader.GetImplementation<IProfiler>(profiler => profiler.ShortName.EqualsWithIgnoreCase(options.Profiler)));
359359

360360
if (options.DisplayAllStatistics)
361361
config.AddColumn(StatisticColumn.AllStatistics);
362-
if (!string.IsNullOrEmpty(options.StatisticalTestThreshold) && Threshold.TryParse(options.StatisticalTestThreshold, out var threshold))
362+
if (options.StatisticalTestThreshold.IsNotBlank() && Threshold.TryParse(options.StatisticalTestThreshold, out var threshold))
363363
config.AddColumn(new StatisticalTestColumn(threshold));
364364

365365
if (options.ArtifactsDirectory != null)
@@ -398,7 +398,7 @@ private static IConfig CreateConfig(CommandLineOptions options, IConfig globalCo
398398
return config;
399399
}
400400

401-
private static Job GetBaseJob(CommandLineOptions options, IConfig globalConfig)
401+
private static Job GetBaseJob(CommandLineOptions options, IConfig? globalConfig)
402402
{
403403
var baseJob =
404404
globalConfig?.GetJobs().SingleOrDefault(job => job.Meta.IsDefault) // global config might define single custom Default job
@@ -466,7 +466,7 @@ private static IEnumerable<Job> Expand(Job baseJob, CommandLineOptions options,
466466
{
467467
yield return baseJob.WithToolchain(InProcessEmitToolchain.Instance);
468468
}
469-
else if (!string.IsNullOrEmpty(options.ClrVersion))
469+
else if (options.ClrVersion.IsNotBlank())
470470
{
471471
var runtime = ClrRuntime.CreateForLocalFullNetFrameworkBuild(options.ClrVersion);
472472
yield return baseJob.WithRuntime(runtime).WithId(runtime.Name); // local builds of .NET Runtime
@@ -637,7 +637,7 @@ private static Job CreateAotJob(Job baseJob, CommandLineOptions options, Runtime
637637

638638
if (options.IlcPackages != null)
639639
builder.UseLocalBuild(options.IlcPackages);
640-
else if (!string.IsNullOrEmpty(options.ILCompilerVersion))
640+
else if (options.ILCompilerVersion.IsNotBlank())
641641
builder.UseNuGet(options.ILCompilerVersion, nuGetFeedUrl);
642642
else
643643
builder.UseNuGet(ilCompilerVersion, nuGetFeedUrl);

src/BenchmarkDotNet/Detectors/Cpu/Linux/LinuxCpuInfoParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ internal static CpuInfo Parse(string cpuInfo, string lscpu)
9191
}
9292

9393
int? coresPerSocket = null;
94-
if (string.IsNullOrEmpty(lscpu) == false)
94+
if (lscpu.IsNotBlank())
9595
{
9696
var lscpuParts = lscpu.Split('\n')
9797
.Where(line => line.Contains(':'))

src/BenchmarkDotNet/Detectors/Cpu/Windows/MosCpuDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public bool IsApplicable() => OsDetector.IsWindows() &&
3434
foreach (var moProcessor in mosProcessor.Get().Cast<ManagementObject>())
3535
{
3636
string name = moProcessor[WmicCpuInfoKeyNames.Name]?.ToString();
37-
if (!string.IsNullOrEmpty(name))
37+
if (name.IsNotBlank())
3838
{
3939
processorModelNames.Add(name);
4040
processorsCount++;

src/BenchmarkDotNet/Detectors/Cpu/Windows/PowershellWmiCpuDetector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Runtime.Versioning;
66
using System.Text.RegularExpressions;
7+
using BenchmarkDotNet.Extensions;
78
using BenchmarkDotNet.Helpers;
89
using Perfolizer.Models;
910

@@ -34,7 +35,7 @@ internal class PowershellWmiCpuDetector : ICpuDetector
3435
string output = ProcessHelper.RunAndReadOutput(PowerShellLocator.LocateOnWindows() ?? "PowerShell",
3536
"Get-CimInstance Win32_Processor -Property " + argList);
3637

37-
if (string.IsNullOrEmpty(output))
38+
if (output.IsBlank())
3839
return null;
3940

4041
return PowershellWmiCpuInfoParser.Parse(output);

src/BenchmarkDotNet/Detectors/Cpu/Windows/WmicCpuDetector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using BenchmarkDotNet.Extensions;
23
using BenchmarkDotNet.Helpers;
34
using BenchmarkDotNet.Portability;
45
using Perfolizer.Models;
@@ -28,7 +29,7 @@ internal class WmicCpuDetector : ICpuDetector
2829
string wmicPath = File.Exists(DefaultWmicPath) ? DefaultWmicPath : "wmic";
2930
string? wmicOutput = ProcessHelper.RunAndReadOutput(wmicPath, $"cpu get {argList} /Format:List");
3031

31-
if (string.IsNullOrEmpty(wmicOutput))
32+
if (wmicOutput.IsBlank())
3233
return null;
3334

3435
return WmicCpuInfoParser.Parse(wmicOutput);

src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using BenchmarkDotNet.Detectors;
1010
using BenchmarkDotNet.Portability;
1111
using Microsoft.Diagnostics.NETCore.Client;
12+
using BenchmarkDotNet.Extensions;
1213

1314
namespace BenchmarkDotNet.Disassemblers
1415
{
@@ -286,7 +287,7 @@ protected void TryTranslateAddressToName(ulong address, bool isAddressPrecodeMD,
286287
var runtime = state.Runtime;
287288

288289
var jitHelperFunctionName = runtime.GetJitHelperFunctionName(address);
289-
if (!string.IsNullOrEmpty(jitHelperFunctionName))
290+
if (jitHelperFunctionName.IsNotBlank())
290291
{
291292
state.AddressToNameMapping.Add(address, jitHelperFunctionName);
292293
return;
@@ -316,7 +317,7 @@ protected void TryTranslateAddressToName(ulong address, bool isAddressPrecodeMD,
316317
}
317318

318319
var methodTableName = runtime.GetTypeByMethodTable(address)?.Name;
319-
if (!string.IsNullOrEmpty(methodTableName))
320+
if (methodTableName.IsNotBlank())
320321
{
321322
state.AddressToNameMapping.Add(address, $"MT_{methodTableName}");
322323
}

src/BenchmarkDotNet/Disassemblers/Exporters/CombinedDisassemblyExporter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using BenchmarkDotNet.Diagnosers;
55
using BenchmarkDotNet.Exporters;
6+
using BenchmarkDotNet.Extensions;
67
using BenchmarkDotNet.Loggers;
78
using BenchmarkDotNet.Reports;
89
using BenchmarkDotNet.Running;
@@ -91,7 +92,7 @@ private void PrintTable(BenchmarkCase[] benchmarksCase, ILogger logger, string t
9192
{
9293
var disassemblyResult = results[benchmark];
9394
logger.WriteLine("<td style=\"vertical-align:top;\"><pre><code>");
94-
foreach (var method in disassemblyResult.Methods.Where(method => string.IsNullOrEmpty(method.Problem)))
95+
foreach (var method in disassemblyResult.Methods.Where(method => method.Problem.IsBlank()))
9596
{
9697
logger.WriteLine(method.Name);
9798

@@ -105,7 +106,7 @@ private void PrintTable(BenchmarkCase[] benchmarksCase, ILogger logger, string t
105106
}
106107

107108
foreach (var withProblems in results[benchmark].Methods
108-
.Where(method => !string.IsNullOrEmpty(method.Problem))
109+
.Where(method => method.Problem.IsNotBlank())
109110
.GroupBy(method => method.Problem))
110111
{
111112
logger.WriteLine(withProblems.Key);

src/BenchmarkDotNet/Disassemblers/Exporters/GithubMarkdownDisassemblyExporter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using BenchmarkDotNet.Diagnosers;
44
using BenchmarkDotNet.Exporters;
5+
using BenchmarkDotNet.Extensions;
56
using BenchmarkDotNet.Loggers;
67
using BenchmarkDotNet.Reports;
78
using BenchmarkDotNet.Running;
@@ -36,7 +37,7 @@ public override void ExportToLog(Summary summary, ILogger logger)
3637
internal static void Export(ILogger logger, DisassemblyResult disassemblyResult, DisassemblyDiagnoserConfig config, bool quotingCode = true)
3738
{
3839
int methodIndex = 0;
39-
foreach (var method in disassemblyResult.Methods.Where(method => string.IsNullOrEmpty(method.Problem)))
40+
foreach (var method in disassemblyResult.Methods.Where(method => method.Problem.IsBlank()))
4041
{
4142
if (quotingCode)
4243
{
@@ -81,7 +82,7 @@ internal static void Export(ILogger logger, DisassemblyResult disassemblyResult,
8182
}
8283

8384
foreach (var withProblems in disassemblyResult.Methods
84-
.Where(method => !string.IsNullOrEmpty(method.Problem))
85+
.Where(method => method.Problem.IsNotBlank())
8586
.GroupBy(method => method.Problem))
8687
{
8788
logger.WriteLine($"**{withProblems.Key}**");

0 commit comments

Comments
 (0)