From 1ffc42b7d2ca7ba6afeda49e4539a522adeee5d8 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 3 Jun 2022 20:12:09 -0400 Subject: [PATCH] refactor: use popcnt --- ChatTwo/GameFunctions/Chat.cs | 5 +++-- ChatTwo/Ui/ChatLog.cs | 4 ++-- ChatTwo/Util/NumUtil.cs | 9 --------- 3 files changed, 5 insertions(+), 13 deletions(-) delete mode 100755 ChatTwo/Util/NumUtil.cs diff --git a/ChatTwo/GameFunctions/Chat.cs b/ChatTwo/GameFunctions/Chat.cs index b7cb1c7..ff542d7 100755 --- a/ChatTwo/GameFunctions/Chat.cs +++ b/ChatTwo/GameFunctions/Chat.cs @@ -1,3 +1,4 @@ +using System.Numerics; using ChatTwo.Code; using ChatTwo.GameFunctions.Types; using ChatTwo.Util; @@ -383,9 +384,9 @@ internal sealed unsafe class Chat : IDisposable { return; } - var bits = NumUtil.NumberOfSetBits((uint) modifier); + var bits = BitOperations.PopCount((uint) modifier); if (!turnedOff.TryGetValue(key, out var previousBits) || previousBits.Item1 < bits) { - turnedOff[key] = (bits, toIntercept); + turnedOff[key] = ((uint) bits, toIntercept); } } diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index a5602c6..6c3a56f 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -301,9 +301,9 @@ internal sealed class ChatLog : IUiComponent { return; } - var bits = NumUtil.NumberOfSetBits((uint) modifier); + var bits = BitOperations.PopCount((uint) modifier); if (!turnedOff.TryGetValue(key, out var previousBits) || previousBits.Item1 < bits) { - turnedOff[key] = (bits, toIntercept); + turnedOff[key] = ((uint) bits, toIntercept); } } diff --git a/ChatTwo/Util/NumUtil.cs b/ChatTwo/Util/NumUtil.cs deleted file mode 100755 index 88b74ba..0000000 --- a/ChatTwo/Util/NumUtil.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace ChatTwo.Util; - -internal static class NumUtil { - internal static uint NumberOfSetBits(uint i) { - i -= (i >> 1) & 0x55555555; - i = (i & 0x33333333) + ((i >> 2) & 0x33333333); - return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; - } -}