From fe5655d1e371bdeb5d8738d9e5291dcaec58559f Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 15 Dec 2020 17:54:44 -0600 Subject: [PATCH] misc cleanups in BizHawk.Common --- BizHawk.sln.DotSettings | 1 + src/BizHawk.Common/Bit.cs | 2 +- src/BizHawk.Common/CustomCollections.cs | 2 +- src/BizHawk.Common/Extensions/BufferExtensions.cs | 2 +- src/BizHawk.Common/Extensions/PathExtensions.cs | 4 ++-- src/BizHawk.Common/Log.cs | 10 +++++----- src/BizHawk.Common/Ranges.cs | 2 -- src/BizHawk.Common/Serializer.cs | 5 +++-- src/BizHawk.Common/VersionInfo.cs | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 78b0c1e635..1bfd3018f5 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -410,6 +410,7 @@ True True True + True True True True diff --git a/src/BizHawk.Common/Bit.cs b/src/BizHawk.Common/Bit.cs index c891722587..16b941d3d5 100644 --- a/src/BizHawk.Common/Bit.cs +++ b/src/BizHawk.Common/Bit.cs @@ -5,7 +5,7 @@ using System.Diagnostics; namespace BizHawk.Common { // I think this is a little faster with uint than with byte - public struct Bit + public readonly struct Bit { private readonly uint _val; diff --git a/src/BizHawk.Common/CustomCollections.cs b/src/BizHawk.Common/CustomCollections.cs index 265f197778..510321c9cd 100644 --- a/src/BizHawk.Common/CustomCollections.cs +++ b/src/BizHawk.Common/CustomCollections.cs @@ -134,7 +134,7 @@ namespace BizHawk.Common { get => TryGetValue(key, out var temp) ? temp - : (base[key] = new TValue()); + : base[key] = new TValue(); set => base[key] = value; } } diff --git a/src/BizHawk.Common/Extensions/BufferExtensions.cs b/src/BizHawk.Common/Extensions/BufferExtensions.cs index 33131a899c..b9f5f68f69 100644 --- a/src/BizHawk.Common/Extensions/BufferExtensions.cs +++ b/src/BizHawk.Common/Extensions/BufferExtensions.cs @@ -72,7 +72,7 @@ namespace BizHawk.Common.BufferExtensions var fidx = 0; int result = Array.FindIndex(array, 0, array.Length, (byte b) => { - fidx = (b == pattern[fidx]) ? fidx + 1 : 0; + fidx = b == pattern[fidx] ? fidx + 1 : 0; return fidx == pattern.Length; }); diff --git a/src/BizHawk.Common/Extensions/PathExtensions.cs b/src/BizHawk.Common/Extensions/PathExtensions.cs index 9c579375b1..e170fdd38b 100644 --- a/src/BizHawk.Common/Extensions/PathExtensions.cs +++ b/src/BizHawk.Common/Extensions/PathExtensions.cs @@ -134,8 +134,8 @@ namespace BizHawk.Common.PathExtensions { var dirPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); ExeDirectoryPath = OSTailoredCode.IsUnixHost - ? (string.IsNullOrEmpty(dirPath) || dirPath == "/" ? string.Empty : dirPath) - : (string.IsNullOrEmpty(dirPath) ? throw new Exception("failed to get location of executable, very bad things must have happened") : dirPath.RemoveSuffix('\\')); + ? string.IsNullOrEmpty(dirPath) || dirPath == "/" ? string.Empty : dirPath + : string.IsNullOrEmpty(dirPath) ? throw new Exception("failed to get location of executable, very bad things must have happened") : dirPath.RemoveSuffix('\\'); DllDirectoryPath = Path.Combine(OSTailoredCode.IsUnixHost && ExeDirectoryPath == string.Empty ? "/" : ExeDirectoryPath, "dll"); // yes, this is a lot of extra code to make sure BizHawk can run in `/` on Unix, but I've made up for it by caching these for the program lifecycle --yoshi } diff --git a/src/BizHawk.Common/Log.cs b/src/BizHawk.Common/Log.cs index 432d4e1c73..4608225881 100644 --- a/src/BizHawk.Common/Log.cs +++ b/src/BizHawk.Common/Log.cs @@ -66,7 +66,7 @@ namespace BizHawk.Common private static readonly bool LogToFile = false; private const string LogFilename = "bizhawk.txt"; - private static StreamWriter writer; + private static StreamWriter _writer; private static void DefaultLogger(string message) { @@ -75,15 +75,15 @@ namespace BizHawk.Common Console.WriteLine(message); } - if (LogToFile && writer == null) + if (LogToFile && _writer == null) { - writer = new StreamWriter(LogFilename); + _writer = new StreamWriter(LogFilename); } if (LogToFile) { - writer.WriteLine(message); - writer.Flush(); + _writer.WriteLine(message); + _writer.Flush(); } } } diff --git a/src/BizHawk.Common/Ranges.cs b/src/BizHawk.Common/Ranges.cs index a61f0df377..cf95b170df 100644 --- a/src/BizHawk.Common/Ranges.cs +++ b/src/BizHawk.Common/Ranges.cs @@ -78,7 +78,6 @@ namespace BizHawk.Common : value; /// true iff is contained in ( is considered to be in the range if it's exactly equal to either bound) - /// public static bool Contains(this Range range, T value) where T : unmanaged, IComparable => !(value.CompareTo(range.Start) < 0 || range.EndInclusive.CompareTo(value) < 0); public static uint Count(this Range range) => (uint) (range.EndInclusive - range.Start + 1); @@ -247,7 +246,6 @@ namespace BizHawk.Common public static Range RangeToExclusive(this ushort start, ushort endExclusive) => MutableRangeToExclusive(start, endExclusive); /// true iff is strictly contained in ( is considered to be OUTSIDE the range if it's exactly equal to either bound) - /// public static bool StrictlyBoundedBy(this T value, Range range) where T : unmanaged, IComparable => range.Start.CompareTo(value) < 0 && value.CompareTo(range.EndInclusive) < 0; } } diff --git a/src/BizHawk.Common/Serializer.cs b/src/BizHawk.Common/Serializer.cs index 28cfd471f9..3138241795 100644 --- a/src/BizHawk.Common/Serializer.cs +++ b/src/BizHawk.Common/Serializer.cs @@ -135,7 +135,8 @@ namespace BizHawk.Common { throw new InvalidOperationException(); } - else if (_isText) + + if (_isText) { SyncEnumText(name, ref val); } @@ -1012,7 +1013,7 @@ namespace BizHawk.Common { if (Present(name)) { - val = int.Parse(this.Item(name)); + val = int.Parse(Item(name)); } } diff --git a/src/BizHawk.Common/VersionInfo.cs b/src/BizHawk.Common/VersionInfo.cs index ddbdcac7dd..bec7f7fb0a 100644 --- a/src/BizHawk.Common/VersionInfo.cs +++ b/src/BizHawk.Common/VersionInfo.cs @@ -50,7 +50,7 @@ namespace BizHawk.Common while (i < 4) { v <<= 8; - v += (i < a.Length && byte.TryParse(a[i], out var b)) ? b : 0U; + v += i < a.Length && byte.TryParse(a[i], out var b) ? b : 0U; i++; } return v;