From 56082ddf44055933e02b921f60c1f7ed4bf3b38a Mon Sep 17 00:00:00 2001 From: zeromus <zeromus@users.noreply.github.com> Date: Fri, 28 Aug 2020 18:50:11 -0400 Subject: [PATCH] move stackalloc in CDL --- src/BizHawk.Client.EmuHawk/tools/CDL.cs | 50 ++++++++++++------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/CDL.cs b/src/BizHawk.Client.EmuHawk/tools/CDL.cs index 5ee7bfef06..001bee85ff 100644 --- a/src/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/src/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -110,11 +110,12 @@ namespace BizHawk.Client.EmuHawk private string[][] _listContents = new string[0][]; - private void UpdateDisplay(bool force) + private unsafe void UpdateDisplay(bool force) { if (!tsbViewUpdate.Checked && !force) return; + int* map = stackalloc int[256]; if (_cdl == null) { @@ -129,35 +130,32 @@ namespace BizHawk.Client.EmuHawk { int[] totals = new int[8]; int total = 0; - unsafe + + for (int i = 0; i < 256; i++) + map[i] = 0; + + fixed (byte* data = kvp.Value) { - int* map = stackalloc int[256]; - for (int i = 0; i < 256; i++) - map[i] = 0; - - fixed (byte* data = kvp.Value) + byte* src = data; + byte* end = data + kvp.Value.Length; + while (src < end) { - byte* src = data; - byte* end = data + kvp.Value.Length; - while (src < end) - { - byte s = *src++; - map[s]++; - } + byte s = *src++; + map[s]++; } + } - for (int i = 0; i < 256; i++) - { - if(i!=0) total += map[i]; - if ((i & 0x01) != 0) totals[0] += map[i]; - if ((i & 0x02) != 0) totals[1] += map[i]; - if ((i & 0x04) != 0) totals[2] += map[i]; - if ((i & 0x08) != 0) totals[3] += map[i]; - if ((i & 0x10) != 0) totals[4] += map[i]; - if ((i & 0x20) != 0) totals[5] += map[i]; - if ((i & 0x40) != 0) totals[6] += map[i]; - if ((i & 0x80) != 0) totals[7] += map[i]; - } + for (int i = 0; i < 256; i++) + { + if(i!=0) total += map[i]; + if ((i & 0x01) != 0) totals[0] += map[i]; + if ((i & 0x02) != 0) totals[1] += map[i]; + if ((i & 0x04) != 0) totals[2] += map[i]; + if ((i & 0x08) != 0) totals[3] += map[i]; + if ((i & 0x10) != 0) totals[4] += map[i]; + if ((i & 0x20) != 0) totals[5] += map[i]; + if ((i & 0x40) != 0) totals[6] += map[i]; + if ((i & 0x80) != 0) totals[7] += map[i]; } var bm = _cdl.GetBlockMap();