mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-19 20:28:24 -05:00
Faster crc16 ccitt
insert lenny face here >4x faster, relative speed is higher for larger input arrays
This commit is contained in:
parent
9699cdefae
commit
8b02f05bd5
|
|
@ -608,24 +608,17 @@ public static bool GetSavesFromFolder(string folderPath, bool deep, out IEnumera
|
|||
/// <returns>Checksum</returns>
|
||||
public static ushort CRC16_CCITT(byte[] data, int start, int length)
|
||||
{
|
||||
const ushort init = 0xFFFF;
|
||||
const ushort poly = 0x1021;
|
||||
|
||||
ushort crc = init;
|
||||
byte top = 0xFF;
|
||||
byte bot = 0xFF;
|
||||
int end = start + length;
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
byte b = data[i];
|
||||
crc ^= (ushort)(b << 8);
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
bool flag = (crc & 0x8000) > 0;
|
||||
crc <<= 1;
|
||||
if (flag)
|
||||
crc ^= poly;
|
||||
}
|
||||
var x = data[i] ^ top;
|
||||
x ^= (x >> 4);
|
||||
top = (byte) (bot ^ (x >> 3) ^ (x << 4));
|
||||
bot = (byte) (x ^ (x << 5));
|
||||
}
|
||||
return crc;
|
||||
return (ushort)(top << 8 | bot);
|
||||
}
|
||||
|
||||
/// <summary>Calculates the CRC16-CCITT checksum over an input byte array.</summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user