diff options
| author | TSRBerry <20988865+TSRBerry@users.noreply.github.com> | 2023-06-28 18:41:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-28 18:41:38 +0200 |
| commit | fc20d9b925b83532a19467293a7cdcbaa4ef3d6b (patch) | |
| tree | ebe0e690b6644d0f825ee80f20e4067855f35cf4 /src/Ryujinx.Common/Utilities | |
| parent | 0a75b73fa43ddadf561ddeb0f923c6f3811c025b (diff) | |
[Ryujinx.Common] Address dotnet-format issues (#5358)
* dotnet format style --severity info
Some changes were manually reverted.
* dotnet format analyzers --serverity info
Some changes have been minimally adapted.
* Restore a few unused methods and variables
* Silence dotnet format IDE0060 warnings
* Silence dotnet format IDE0059 warnings
* Address or silence dotnet format IDE1006 warnings
* Address dotnet format CA1816 warnings
* Address or silence dotnet format CA2211 warnings
* Silence CA1806 and CA1834 issues
* Fix formatting for switch expressions
* Address most dotnet format whitespace warnings
* Apply dotnet format whitespace formatting
A few of them have been manually reverted and the corresponding warning was silenced
* Revert formatting changes for while and for-loops
* Format if-blocks correctly
* Run dotnet format whitespace after rebase
* Run dotnet format style after rebase
* Run dotnet format analyzers after rebase
* Run dotnet format after rebase and remove unused usings
- analyzers
- style
- whitespace
* Add comments to disabled warnings
* Remove a few unused parameters
* Replace MmeShadowScratch with Array256<uint>
* Simplify properties and array initialization, Use const when possible, Remove trailing commas
* Run dotnet format after rebase
* Address IDE0251 warnings
* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"
This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.
* dotnet format whitespace after rebase
* First dotnet format pass
* Second dotnet format pass
* Fix build issues
* Fix StructArrayHelpers.cs
* Apply suggestions from code review
Co-authored-by: Ac_K <Acoustik666@gmail.com>
* Fix return statements
* Fix naming rule violations
* Update src/Ryujinx.Common/Utilities/StreamUtils.cs
Co-authored-by: Ac_K <Acoustik666@gmail.com>
* Add trailing commas
* Address review feedback
* Address review feedback
* Rename remaining type parameters to TKey and TValue
* Fix manual formatting for logging levels
* Fix spacing before comments
---------
Co-authored-by: Ac_K <Acoustik666@gmail.com>
Diffstat (limited to 'src/Ryujinx.Common/Utilities')
| -rw-r--r-- | src/Ryujinx.Common/Utilities/BitUtils.cs | 17 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/BitfieldExtensions.cs | 2 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/Buffers.cs | 4 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/CommonJsonContext.cs | 2 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/EmbeddedResources.cs | 69 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/HexUtils.cs | 34 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/JsonHelper.cs | 14 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/MessagePackObjectFormatter.cs | 18 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/NetworkHelpers.cs | 4 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/StreamUtils.cs | 24 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/TypedStringEnumConverter.cs | 2 | ||||
| -rw-r--r-- | src/Ryujinx.Common/Utilities/UInt128Utils.cs | 2 |
12 files changed, 86 insertions, 106 deletions
diff --git a/src/Ryujinx.Common/Utilities/BitUtils.cs b/src/Ryujinx.Common/Utilities/BitUtils.cs index f885ce84..0bf9c8ac 100644 --- a/src/Ryujinx.Common/Utilities/BitUtils.cs +++ b/src/Ryujinx.Common/Utilities/BitUtils.cs @@ -1,4 +1,3 @@ -using System; using System.Numerics; namespace Ryujinx.Common @@ -27,10 +26,10 @@ namespace Ryujinx.Common { value--; - value |= (value >> 1); - value |= (value >> 2); - value |= (value >> 4); - value |= (value >> 8); + value |= (value >> 1); + value |= (value >> 2); + value |= (value >> 4); + value |= (value >> 8); value |= (value >> 16); return ++value; @@ -48,10 +47,10 @@ namespace Ryujinx.Common private static ulong ReverseBits64(ulong value) { - value = ((value & 0xaaaaaaaaaaaaaaaa) >> 1 ) | ((value & 0x5555555555555555) << 1 ); - value = ((value & 0xcccccccccccccccc) >> 2 ) | ((value & 0x3333333333333333) << 2 ); - value = ((value & 0xf0f0f0f0f0f0f0f0) >> 4 ) | ((value & 0x0f0f0f0f0f0f0f0f) << 4 ); - value = ((value & 0xff00ff00ff00ff00) >> 8 ) | ((value & 0x00ff00ff00ff00ff) << 8 ); + value = ((value & 0xaaaaaaaaaaaaaaaa) >> 1) | ((value & 0x5555555555555555) << 1); + value = ((value & 0xcccccccccccccccc) >> 2) | ((value & 0x3333333333333333) << 2); + value = ((value & 0xf0f0f0f0f0f0f0f0) >> 4) | ((value & 0x0f0f0f0f0f0f0f0f) << 4); + value = ((value & 0xff00ff00ff00ff00) >> 8) | ((value & 0x00ff00ff00ff00ff) << 8); value = ((value & 0xffff0000ffff0000) >> 16) | ((value & 0x0000ffff0000ffff) << 16); return (value >> 32) | (value << 32); diff --git a/src/Ryujinx.Common/Utilities/BitfieldExtensions.cs b/src/Ryujinx.Common/Utilities/BitfieldExtensions.cs index ca429944..8e9b696e 100644 --- a/src/Ryujinx.Common/Utilities/BitfieldExtensions.cs +++ b/src/Ryujinx.Common/Utilities/BitfieldExtensions.cs @@ -54,4 +54,4 @@ namespace Ryujinx.Common.Utilities return (value & ~mask) | ((toInsert << lsb) & mask); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Common/Utilities/Buffers.cs b/src/Ryujinx.Common/Utilities/Buffers.cs index d614bfc4..c85b8713 100644 --- a/src/Ryujinx.Common/Utilities/Buffers.cs +++ b/src/Ryujinx.Common/Utilities/Buffers.cs @@ -9,8 +9,8 @@ namespace Ryujinx.Common.Utilities [StructLayout(LayoutKind.Sequential, Size = 16)] public struct Buffer16 { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] private ulong _dummy0; - [DebuggerBrowsable(DebuggerBrowsableState.Never)] private ulong _dummy1; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy0; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1; public byte this[int i] { diff --git a/src/Ryujinx.Common/Utilities/CommonJsonContext.cs b/src/Ryujinx.Common/Utilities/CommonJsonContext.cs index d7b3f78c..93f06512 100644 --- a/src/Ryujinx.Common/Utilities/CommonJsonContext.cs +++ b/src/Ryujinx.Common/Utilities/CommonJsonContext.cs @@ -8,4 +8,4 @@ namespace Ryujinx.Common.Utilities public partial class CommonJsonContext : JsonSerializerContext { } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Common/Utilities/EmbeddedResources.cs b/src/Ryujinx.Common/Utilities/EmbeddedResources.cs index 22b55f16..a4facc2e 100644 --- a/src/Ryujinx.Common/Utilities/EmbeddedResources.cs +++ b/src/Ryujinx.Common/Utilities/EmbeddedResources.cs @@ -1,4 +1,3 @@ -using Ryujinx.Common.Memory; using Ryujinx.Common.Utilities; using System; using System.IO; @@ -10,11 +9,11 @@ namespace Ryujinx.Common { public static class EmbeddedResources { - private readonly static Assembly ResourceAssembly; + private readonly static Assembly _resourceAssembly; static EmbeddedResources() { - ResourceAssembly = Assembly.GetAssembly(typeof(EmbeddedResources)); + _resourceAssembly = Assembly.GetAssembly(typeof(EmbeddedResources)); } public static byte[] Read(string filename) @@ -33,28 +32,24 @@ namespace Ryujinx.Common public static byte[] Read(Assembly assembly, string filename) { - using (var stream = GetStream(assembly, filename)) + using var stream = GetStream(assembly, filename); + if (stream == null) { - if (stream == null) - { - return null; - } - - return StreamUtils.StreamToBytes(stream); + return null; } + + return StreamUtils.StreamToBytes(stream); } public async static Task<byte[]> ReadAsync(Assembly assembly, string filename) { - using (var stream = GetStream(assembly, filename)) + using var stream = GetStream(assembly, filename); + if (stream == null) { - if (stream == null) - { - return null; - } - - return await StreamUtils.StreamToBytesAsync(stream); + return null; } + + return await StreamUtils.StreamToBytesAsync(stream); } public static string ReadAllText(string filename) @@ -73,34 +68,26 @@ namespace Ryujinx.Common public static string ReadAllText(Assembly assembly, string filename) { - using (var stream = GetStream(assembly, filename)) + using var stream = GetStream(assembly, filename); + if (stream == null) { - if (stream == null) - { - return null; - } - - using (var reader = new StreamReader(stream)) - { - return reader.ReadToEnd(); - } + return null; } + + using var reader = new StreamReader(stream); + return reader.ReadToEnd(); } public async static Task<string> ReadAllTextAsync(Assembly assembly, string filename) { - using (var stream = GetStream(assembly, filename)) + using var stream = GetStream(assembly, filename); + if (stream == null) { - if (stream == null) - { - return null; - } - - using (var reader = new StreamReader(stream)) - { - return await reader.ReadToEndAsync(); - } + return null; } + + using var reader = new StreamReader(stream); + return await reader.ReadToEndAsync(); } public static Stream GetStream(string filename) @@ -112,8 +99,8 @@ namespace Ryujinx.Common public static Stream GetStream(Assembly assembly, string filename) { - var namespace_ = assembly.GetName().Name; - var manifestUri = namespace_ + "." + filename.Replace('/', '.'); + var @namespace = assembly.GetName().Name; + var manifestUri = @namespace + "." + filename.Replace('/', '.'); var stream = assembly.GetManifestResourceStream(manifestUri); @@ -142,7 +129,7 @@ namespace Ryujinx.Common } } - return (ResourceAssembly, filename); + return (_resourceAssembly, filename); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Common/Utilities/HexUtils.cs b/src/Ryujinx.Common/Utilities/HexUtils.cs index 63587cea..4690eaa1 100644 --- a/src/Ryujinx.Common/Utilities/HexUtils.cs +++ b/src/Ryujinx.Common/Utilities/HexUtils.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Common { public static class HexUtils { - private static readonly char[] HexChars = "0123456789ABCDEF".ToCharArray(); + private static readonly char[] _hexChars = "0123456789ABCDEF".ToCharArray(); private const int HexTableColumnWidth = 8; private const int HexTableColumnSpace = 3; @@ -39,20 +39,20 @@ namespace Ryujinx.Common int expectedLines = (bytesLength + bytesPerLine - 1) / bytesPerLine; - StringBuilder result = new StringBuilder(expectedLines * lineLength); + StringBuilder result = new(expectedLines * lineLength); for (int i = 0; i < bytesLength; i += bytesPerLine) { - line[0] = HexChars[(i >> 28) & 0xF]; - line[1] = HexChars[(i >> 24) & 0xF]; - line[2] = HexChars[(i >> 20) & 0xF]; - line[3] = HexChars[(i >> 16) & 0xF]; - line[4] = HexChars[(i >> 12) & 0xF]; - line[5] = HexChars[(i >> 8) & 0xF]; - line[6] = HexChars[(i >> 4) & 0xF]; - line[7] = HexChars[(i >> 0) & 0xF]; - - int hexColumn = firstHexColumn; + line[0] = _hexChars[(i >> 28) & 0xF]; + line[1] = _hexChars[(i >> 24) & 0xF]; + line[2] = _hexChars[(i >> 20) & 0xF]; + line[3] = _hexChars[(i >> 16) & 0xF]; + line[4] = _hexChars[(i >> 12) & 0xF]; + line[5] = _hexChars[(i >> 8) & 0xF]; + line[6] = _hexChars[(i >> 4) & 0xF]; + line[7] = _hexChars[(i >> 0) & 0xF]; + + int hexColumn = firstHexColumn; int charColumn = firstCharColumn; for (int j = 0; j < bytesPerLine; j++) @@ -64,17 +64,17 @@ namespace Ryujinx.Common if (i + j >= bytesLength) { - line[hexColumn] = ' '; + line[hexColumn] = ' '; line[hexColumn + 1] = ' '; - line[charColumn] = ' '; + line[charColumn] = ' '; } else { byte b = bytes[i + j]; - line[hexColumn] = HexChars[(b >> 4) & 0xF]; - line[hexColumn + 1] = HexChars[b & 0xF]; - line[charColumn] = (b < 32 ? '·' : (char)b); + line[hexColumn] = _hexChars[(b >> 4) & 0xF]; + line[hexColumn + 1] = _hexChars[b & 0xF]; + line[charColumn] = (b < 32 ? '·' : (char)b); } hexColumn += 3; diff --git a/src/Ryujinx.Common/Utilities/JsonHelper.cs b/src/Ryujinx.Common/Utilities/JsonHelper.cs index 9a2d6f18..d4ecf5e9 100644 --- a/src/Ryujinx.Common/Utilities/JsonHelper.cs +++ b/src/Ryujinx.Common/Utilities/JsonHelper.cs @@ -7,7 +7,7 @@ namespace Ryujinx.Common.Utilities { public class JsonHelper { - private static readonly JsonNamingPolicy SnakeCasePolicy = new SnakeCaseNamingPolicy(); + private static readonly JsonNamingPolicy _snakeCasePolicy = new SnakeCaseNamingPolicy(); private const int DefaultFileWriteBufferSize = 4096; /// <summary> @@ -21,11 +21,11 @@ namespace Ryujinx.Common.Utilities { JsonSerializerOptions options = new() { - DictionaryKeyPolicy = SnakeCasePolicy, - PropertyNamingPolicy = SnakeCasePolicy, - WriteIndented = indented, - AllowTrailingCommas = true, - ReadCommentHandling = JsonCommentHandling.Skip + DictionaryKeyPolicy = _snakeCasePolicy, + PropertyNamingPolicy = _snakeCasePolicy, + WriteIndented = indented, + AllowTrailingCommas = true, + ReadCommentHandling = JsonCommentHandling.Skip, }; return options; @@ -95,4 +95,4 @@ namespace Ryujinx.Common.Utilities } } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Common/Utilities/MessagePackObjectFormatter.cs b/src/Ryujinx.Common/Utilities/MessagePackObjectFormatter.cs index 3714bec0..a7c596ba 100644 --- a/src/Ryujinx.Common/Utilities/MessagePackObjectFormatter.cs +++ b/src/Ryujinx.Common/Utilities/MessagePackObjectFormatter.cs @@ -12,10 +12,8 @@ namespace Ryujinx.Common.Utilities { return Format(obj); } - else - { - return obj.ToString(); - } + + return obj.ToString(); } public static string Format(MessagePackObject obj) @@ -179,19 +177,17 @@ namespace Ryujinx.Common.Utilities { return unchecked((char)('0' + b)); } - else - { - return unchecked((char)('A' + (b - 10))); - } + + return unchecked((char)('A' + (b - 10))); } internal class IndentedStringBuilder { const string DefaultIndent = " "; - private int _indentCount = 0; - private int _newLineIndex = 0; - private StringBuilder _builder; + private int _indentCount; + private int _newLineIndex; + private readonly StringBuilder _builder; public string IndentString { get; set; } = DefaultIndent; diff --git a/src/Ryujinx.Common/Utilities/NetworkHelpers.cs b/src/Ryujinx.Common/Utilities/NetworkHelpers.cs index b2f6f45d..e48ff269 100644 --- a/src/Ryujinx.Common/Utilities/NetworkHelpers.cs +++ b/src/Ryujinx.Common/Utilities/NetworkHelpers.cs @@ -30,7 +30,7 @@ namespace Ryujinx.Common.Utilities return (null, null); } - IPInterfaceProperties targetProperties = null; + IPInterfaceProperties targetProperties = null; UnicastIPAddressInformation targetAddressInfo = null; NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); @@ -63,4 +63,4 @@ namespace Ryujinx.Common.Utilities return (targetProperties, targetAddressInfo); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Common/Utilities/StreamUtils.cs b/src/Ryujinx.Common/Utilities/StreamUtils.cs index da97188d..4d090fe9 100644 --- a/src/Ryujinx.Common/Utilities/StreamUtils.cs +++ b/src/Ryujinx.Common/Utilities/StreamUtils.cs @@ -1,5 +1,4 @@ -using Microsoft.IO; -using Ryujinx.Common.Memory; +using Ryujinx.Common.Memory; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -10,22 +9,21 @@ namespace Ryujinx.Common.Utilities { public static byte[] StreamToBytes(Stream input) { - using (MemoryStream stream = MemoryStreamManager.Shared.GetStream()) - { - input.CopyTo(stream); + using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); - return stream.ToArray(); - } + + input.CopyTo(stream); + + return stream.ToArray(); } public static async Task<byte[]> StreamToBytesAsync(Stream input, CancellationToken cancellationToken = default) { - using (MemoryStream stream = MemoryStreamManager.Shared.GetStream()) - { - await input.CopyToAsync(stream, cancellationToken); + using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); + + await input.CopyToAsync(stream, cancellationToken); - return stream.ToArray(); - } + return stream.ToArray(); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Common/Utilities/TypedStringEnumConverter.cs b/src/Ryujinx.Common/Utilities/TypedStringEnumConverter.cs index 73765129..9c575d69 100644 --- a/src/Ryujinx.Common/Utilities/TypedStringEnumConverter.cs +++ b/src/Ryujinx.Common/Utilities/TypedStringEnumConverter.cs @@ -34,4 +34,4 @@ namespace Ryujinx.Common.Utilities writer.WriteStringValue(value.ToString()); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Common/Utilities/UInt128Utils.cs b/src/Ryujinx.Common/Utilities/UInt128Utils.cs index af8521b4..11385535 100644 --- a/src/Ryujinx.Common/Utilities/UInt128Utils.cs +++ b/src/Ryujinx.Common/Utilities/UInt128Utils.cs @@ -15,4 +15,4 @@ namespace Ryujinx.Common.Utilities return new UInt128((ulong)Random.Shared.NextInt64(), (ulong)Random.Shared.NextInt64()); } } -}
\ No newline at end of file +} |
