1 回答
TA贡献2041条经验 获得超4个赞
如果一次 8 字节的方面对您来说效果很好,并且您确定需要额外的性能,则可以扩展该方法以单独覆盖剩余的字节 - 最多 7 个字节:
public static unsafe void XOr64(byte[] oldBlock, byte[] newBlock)
{
// First XOR as many 64-bit blocks as possible, for the sake of speed
fixed (byte* byteA = oldBlock)
fixed (byte* byteB = newBlock)
{
long* ppA = (long*) byteA;
long* ppB = (long*) byteB;
int chunks = oldBlock.Length / 8;
for (int p = 0; p < chunks; p++)
{
*ppA ^= *ppB;
ppA++;
ppB++;
}
}
// Now cover any remaining bytes one byte at a time. We've
// already handled chunks * 8 bytes, so start there.
for (int index = chunks * 8; index < oldBlock.Length; index++)
{
oldBlock[index] ^= newBlock[index];
}
}
- 1 回答
- 0 关注
- 187 浏览
添加回答
举报