From 3fa0f71a24c7f4c0b6b24044c27666f5c4a66ce1 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 4 Apr 2019 01:18:32 +1000 Subject: [PATCH] Inline ToHexString extension where param numdigits is constant --- BizHawk.Client.Common/tools/Watch/ByteWatch.cs | 2 +- BizHawk.Client.Common/tools/Watch/DWordWatch.cs | 2 +- BizHawk.Client.Common/tools/Watch/WordWatch.cs | 2 +- .../config/NES/NESSyncSettingsForm.cs | 2 +- .../tools/SNES/SNESGraphicsDebugger.cs | 6 +++--- BizHawk.Common/Extensions/NumberExtensions.cs | 10 ---------- BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs | 2 +- 7 files changed, 8 insertions(+), 18 deletions(-) diff --git a/BizHawk.Client.Common/tools/Watch/ByteWatch.cs b/BizHawk.Client.Common/tools/Watch/ByteWatch.cs index 50531248ba..f7cc79de01 100644 --- a/BizHawk.Client.Common/tools/Watch/ByteWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/ByteWatch.cs @@ -190,7 +190,7 @@ namespace BizHawk.Client.Common case DisplayType.Signed: return ((sbyte)val).ToString(); case DisplayType.Hex: - return val.ToHexString(2); + return $"{val:X2}"; case DisplayType.Binary: return Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " "); } diff --git a/BizHawk.Client.Common/tools/Watch/DWordWatch.cs b/BizHawk.Client.Common/tools/Watch/DWordWatch.cs index 360966dac0..10ade39772 100644 --- a/BizHawk.Client.Common/tools/Watch/DWordWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/DWordWatch.cs @@ -215,7 +215,7 @@ namespace BizHawk.Client.Common case DisplayType.Signed: return ((int)val).ToString(); case DisplayType.Hex: - return val.ToHexString(8); + return $"{val:X8}"; case DisplayType.FixedPoint_20_12: return $"{(int)val / 4096.0:0.######}"; case DisplayType.FixedPoint_16_16: diff --git a/BizHawk.Client.Common/tools/Watch/WordWatch.cs b/BizHawk.Client.Common/tools/Watch/WordWatch.cs index be6d461bf4..51c16e68ea 100644 --- a/BizHawk.Client.Common/tools/Watch/WordWatch.cs +++ b/BizHawk.Client.Common/tools/Watch/WordWatch.cs @@ -202,7 +202,7 @@ namespace BizHawk.Client.Common case DisplayType.Signed: return ((short)val).ToString(); case DisplayType.Hex: - return val.ToHexString(4); + return $"{val:X4}"; case DisplayType.FixedPoint_12_4: return $"{val / 16.0:F4}"; case DisplayType.Binary: diff --git a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs index 2da2106c6f..b343fe4355 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSyncSettingsForm.cs @@ -43,7 +43,7 @@ namespace BizHawk.Client.EmuHawk var sb = new StringBuilder(); foreach (var b in _syncSettings.InitialWRamStatePattern) { - sb.Append(b.ToHexString(2)); + sb.Append($"{b:X2}"); } RamPatternOverrideBox.Text = sb.ToString(); diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs index 235c17a6c3..5333e9b2bc 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs @@ -130,8 +130,8 @@ namespace BizHawk.Client.EmuHawk string FormatVramAddress(int address) { int excess = address & 1023; - if (excess != 0) return $"@{address.ToHexString(4)}"; - else return $"@{address.ToHexString(4)} ({address / 1024}K)"; + if (excess != 0) return $"@{address:X4}"; + else return $"@{address:X4} ({address / 1024}K)"; } public void NewUpdate(ToolFormUpdateType type) { } @@ -786,7 +786,7 @@ namespace BizHawk.Client.EmuHawk addr *= 2; addr &= 0xFFFF; - txtMapEntryTileAddr.Text = $"@{addr.ToHexString(4)}"; + txtMapEntryTileAddr.Text = $"@{addr:X4}"; } void UpdateColorDetails() diff --git a/BizHawk.Common/Extensions/NumberExtensions.cs b/BizHawk.Common/Extensions/NumberExtensions.cs index cd0ee12369..1b7aff6326 100644 --- a/BizHawk.Common/Extensions/NumberExtensions.cs +++ b/BizHawk.Common/Extensions/NumberExtensions.cs @@ -15,16 +15,6 @@ namespace BizHawk.Common.NumberExtensions return string.Format($"{{0:X{numdigits}}}", n); } - public static string ToHexString(this byte n, int numdigits) - { - return string.Format($"{{0:X{numdigits}}}", n); - } - - public static string ToHexString(this ushort n, int numdigits) - { - return string.Format($"{{0:X{numdigits}}}", n); - } - public static string ToHexString(this long n, int numdigits) { return string.Format($"{{0:X{numdigits}}}", n); diff --git a/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs b/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs index 8560300319..774f25ff1e 100644 --- a/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs +++ b/BizHawk.Emulation.Cores/CPUs/Z80A/Z80A.cs @@ -747,7 +747,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80A for (ushort i = 0; i < bytes_read; i++) { - byte_code += ReadMemory((ushort)(RegPC + i)).ToHexString(2); + byte_code += $"{ReadMemory((ushort)(RegPC + i)):X2}"; if (i < (bytes_read - 1)) { byte_code += " ";