misc cleanups in BizHawk.Common

This commit is contained in:
adelikat 2020-12-15 17:54:44 -06:00
parent cb6ef03982
commit fe5655d1e3
9 changed files with 15 additions and 15 deletions

View File

@ -410,6 +410,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=mednadisc/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=mednadisc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mednafen/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Mednafen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mednafen_0027s/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Mednafen_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Memset/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=minipsf/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=minipsf/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Missle/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Missle/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mmsys/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=mmsys/@EntryIndexedValue">True</s:Boolean>

View File

@ -5,7 +5,7 @@ using System.Diagnostics;
namespace BizHawk.Common namespace BizHawk.Common
{ {
// I think this is a little faster with uint than with byte // I think this is a little faster with uint than with byte
public struct Bit public readonly struct Bit
{ {
private readonly uint _val; private readonly uint _val;

View File

@ -134,7 +134,7 @@ namespace BizHawk.Common
{ {
get => TryGetValue(key, out var temp) get => TryGetValue(key, out var temp)
? temp ? temp
: (base[key] = new TValue()); : base[key] = new TValue();
set => base[key] = value; set => base[key] = value;
} }
} }

View File

@ -72,7 +72,7 @@ namespace BizHawk.Common.BufferExtensions
var fidx = 0; var fidx = 0;
int result = Array.FindIndex(array, 0, array.Length, (byte b) => 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; return fidx == pattern.Length;
}); });

View File

@ -134,8 +134,8 @@ namespace BizHawk.Common.PathExtensions
{ {
var dirPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); var dirPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
ExeDirectoryPath = OSTailoredCode.IsUnixHost ExeDirectoryPath = OSTailoredCode.IsUnixHost
? (string.IsNullOrEmpty(dirPath) || dirPath == "/" ? string.Empty : dirPath) ? 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) ? 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"); 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 // 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
} }

View File

@ -66,7 +66,7 @@ namespace BizHawk.Common
private static readonly bool LogToFile = false; private static readonly bool LogToFile = false;
private const string LogFilename = "bizhawk.txt"; private const string LogFilename = "bizhawk.txt";
private static StreamWriter writer; private static StreamWriter _writer;
private static void DefaultLogger(string message) private static void DefaultLogger(string message)
{ {
@ -75,15 +75,15 @@ namespace BizHawk.Common
Console.WriteLine(message); Console.WriteLine(message);
} }
if (LogToFile && writer == null) if (LogToFile && _writer == null)
{ {
writer = new StreamWriter(LogFilename); _writer = new StreamWriter(LogFilename);
} }
if (LogToFile) if (LogToFile)
{ {
writer.WriteLine(message); _writer.WriteLine(message);
writer.Flush(); _writer.Flush();
} }
} }
} }

View File

@ -78,7 +78,6 @@ namespace BizHawk.Common
: value; : value;
/// <returns>true iff <paramref name="value"/> is contained in <paramref name="range"/> (<paramref name="value"/> is considered to be in the range if it's exactly equal to either bound)</returns> /// <returns>true iff <paramref name="value"/> is contained in <paramref name="range"/> (<paramref name="value"/> is considered to be in the range if it's exactly equal to either bound)</returns>
/// <seealso cref="StrictlyBoundedBy"/>
public static bool Contains<T>(this Range<T> range, T value) where T : unmanaged, IComparable<T> => !(value.CompareTo(range.Start) < 0 || range.EndInclusive.CompareTo(value) < 0); public static bool Contains<T>(this Range<T> range, T value) where T : unmanaged, IComparable<T> => !(value.CompareTo(range.Start) < 0 || range.EndInclusive.CompareTo(value) < 0);
public static uint Count(this Range<byte> range) => (uint) (range.EndInclusive - range.Start + 1); public static uint Count(this Range<byte> range) => (uint) (range.EndInclusive - range.Start + 1);
@ -247,7 +246,6 @@ namespace BizHawk.Common
public static Range<ushort> RangeToExclusive(this ushort start, ushort endExclusive) => MutableRangeToExclusive(start, endExclusive); public static Range<ushort> RangeToExclusive(this ushort start, ushort endExclusive) => MutableRangeToExclusive(start, endExclusive);
/// <returns>true iff <paramref name="value"/> is strictly contained in <paramref name="range"/> (<paramref name="value"/> is considered to be OUTSIDE the range if it's exactly equal to either bound)</returns> /// <returns>true iff <paramref name="value"/> is strictly contained in <paramref name="range"/> (<paramref name="value"/> is considered to be OUTSIDE the range if it's exactly equal to either bound)</returns>
/// <seealso cref="Contains"/>
public static bool StrictlyBoundedBy<T>(this T value, Range<T> range) where T : unmanaged, IComparable<T> => range.Start.CompareTo(value) < 0 && value.CompareTo(range.EndInclusive) < 0; public static bool StrictlyBoundedBy<T>(this T value, Range<T> range) where T : unmanaged, IComparable<T> => range.Start.CompareTo(value) < 0 && value.CompareTo(range.EndInclusive) < 0;
} }
} }

View File

@ -135,7 +135,8 @@ namespace BizHawk.Common
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
else if (_isText)
if (_isText)
{ {
SyncEnumText(name, ref val); SyncEnumText(name, ref val);
} }
@ -1012,7 +1013,7 @@ namespace BizHawk.Common
{ {
if (Present(name)) if (Present(name))
{ {
val = int.Parse(this.Item(name)); val = int.Parse(Item(name));
} }
} }

View File

@ -50,7 +50,7 @@ namespace BizHawk.Common
while (i < 4) while (i < 4)
{ {
v <<= 8; 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++; i++;
} }
return v; return v;