refactor: use popcnt

This commit is contained in:
Anna 2022-06-03 20:12:09 -04:00
parent a5f93fd194
commit 1ffc42b7d2
3 changed files with 5 additions and 13 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}