Skip to content

Commit dd50927

Browse files
committed
chore: reduce simplejson dependencies
1 parent 31b9411 commit dd50927

File tree

12 files changed

+487
-364
lines changed

12 files changed

+487
-364
lines changed

src/BenchmarkDotNet/BenchmarkDotNet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
2828
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
2929
<PackageReference Include="System.Management" Version="10.0.1" />
30+
<PackageReference Include="System.Text.Json" Version="10.0.1" />
3031
</ItemGroup>
3132
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
3233
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
using System;
1+
using BenchmarkDotNet.Serialization;
22
using System.Linq;
3-
using SimpleJson;
3+
using System.Text.Json.Serialization;
44

55
#nullable enable
66

77
namespace BenchmarkDotNet.Disassemblers
88
{
99
internal struct ClrMdArgs(int processId, string typeName, string methodName, bool printSource, int maxDepth, string syntax, string tfm, string[] filters, string resultsPath = "")
1010
{
11+
[JsonIgnore]
1112
internal int ProcessId = processId;
12-
internal string TypeName = typeName;
13+
14+
[JsonIgnore]
15+
internal string TypeName = typeName ?? "";
16+
17+
[JsonInclude]
1318
internal string MethodName = methodName;
19+
20+
[JsonInclude]
1421
internal bool PrintSource = printSource;
22+
23+
[JsonInclude]
1524
internal int MaxDepth = methodName == DisassemblerConstants.DisassemblerEntryMethodName && maxDepth != int.MaxValue ? maxDepth + 1 : maxDepth;
25+
26+
[JsonInclude]
1627
internal string[] Filters = filters;
28+
29+
[JsonInclude]
1730
internal string Syntax = syntax;
31+
32+
[JsonInclude]
1833
internal string TargetFrameworkMoniker = tfm;
34+
35+
[JsonInclude]
1936
internal string ResultsPath = resultsPath;
2037

2138
internal static ClrMdArgs FromArgs(string[] args)
@@ -30,46 +47,5 @@ internal static ClrMdArgs FromArgs(string[] args)
3047
tfm: args[7],
3148
filters: [.. args.Skip(8)]
3249
);
33-
34-
internal readonly string Serialize()
35-
{
36-
SimpleJsonSerializer.CurrentJsonSerializerStrategy.Indent = false;
37-
var jsonObject = new JsonObject()
38-
{
39-
[nameof(MethodName)] = MethodName,
40-
[nameof(PrintSource)] = PrintSource,
41-
[nameof(MaxDepth)] = MaxDepth,
42-
[nameof(Syntax)] = Syntax,
43-
[nameof(TargetFrameworkMoniker)] = TargetFrameworkMoniker,
44-
[nameof(ResultsPath)] = ResultsPath,
45-
};
46-
var filters = new JsonArray(Filters.Length);
47-
foreach (var filter in Filters)
48-
{
49-
filters.Add(filter);
50-
}
51-
jsonObject[nameof(Filters)] = filters;
52-
return jsonObject.ToString();
53-
}
54-
55-
internal void Deserialize(string? json)
56-
{
57-
var jsonObject = SimpleJsonSerializer.DeserializeObject<JsonObject>(json);
58-
if (jsonObject == null)
59-
return;
60-
61-
MethodName = (string)jsonObject[nameof(MethodName)];
62-
PrintSource = (bool)jsonObject[nameof(PrintSource)];
63-
MaxDepth = Convert.ToInt32(jsonObject[nameof(MaxDepth)]);
64-
Syntax = (string) jsonObject[nameof(Syntax)];
65-
TargetFrameworkMoniker = (string) jsonObject[nameof(TargetFrameworkMoniker)];
66-
ResultsPath = (string) jsonObject[nameof(ResultsPath)];
67-
var filters = (JsonArray) jsonObject[nameof(Filters)];
68-
Filters = new string[filters.Count];
69-
for (int i = 0; i < filters.Count; ++i)
70-
{
71-
Filters[i] = (string) filters[i];
72-
}
73-
}
7450
}
7551
}

src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private static ulong GetMinValidAddress()
2626
if (OsDetector.IsWindows())
2727
return ushort.MaxValue + 1;
2828
if (OsDetector.IsLinux())
29-
return (ulong) Environment.SystemPageSize;
29+
return (ulong)Environment.SystemPageSize;
3030
if (OsDetector.IsMacOS())
3131
return RuntimeInformation.GetCurrentPlatform() switch
3232
{
@@ -121,8 +121,8 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)
121121
return new DisassemblyResult
122122
{
123123
Methods = filteredMethods,
124-
SerializedAddressToNameMapping = state.AddressToNameMapping.Select(x => new DisassemblyResult.MutablePair { Key = x.Key, Value = x.Value }).ToArray(),
125-
PointerSize = (uint) IntPtr.Size
124+
AddressToNameMapping = state.AddressToNameMapping,
125+
PointerSize = (uint)IntPtr.Size
126126
};
127127
}
128128

@@ -296,7 +296,7 @@ protected void TryTranslateAddressToName(ulong address, bool isAddressPrecodeMD,
296296
}
297297

298298
var method = runtime.GetMethodByInstructionPointer(address);
299-
if (method is null && (address & ((uint) runtime.DataTarget.DataReader.PointerSize - 1)) == 0
299+
if (method is null && (address & ((uint)runtime.DataTarget.DataReader.PointerSize - 1)) == 0
300300
&& runtime.DataTarget.DataReader.ReadPointer(address, out ulong newAddress) && IsValidAddress(newAddress))
301301
{
302302
method = runtime.GetMethodByInstructionPointer(newAddress);

0 commit comments

Comments
 (0)