Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ApplyMask() [2/2]

static unsafe int System.Net.WebSockets.ManagedWebSocket.ApplyMask ( Span< byte > toMask,
int mask,
int maskIndex )
inlinestaticprivate

Definition at line 1412 of file ManagedWebSocket.cs.

1413 {
1414 fixed (byte* ptr = &MemoryMarshal.GetReference(toMask))
1415 {
1416 byte* ptr2 = ptr;
1417 byte* ptr3 = ptr + toMask.Length;
1418 byte* ptr4 = (byte*)(&mask);
1419 if (ptr3 - ptr2 >= 4)
1420 {
1421 while ((ulong)ptr2 % 4uL != 0L)
1422 {
1423 byte* intPtr = ptr2++;
1424 *intPtr ^= ptr4[maskIndex];
1425 maskIndex = (maskIndex + 1) & 3;
1426 }
1427 int num = (int)((!BitConverter.IsLittleEndian) ? BitOperations.RotateLeft((uint)mask, maskIndex * 8) : BitOperations.RotateRight((uint)mask, maskIndex * 8));
1428 if (Vector.IsHardwareAccelerated && Vector<byte>.Count % 4 == 0 && ptr3 - ptr2 >= Vector<byte>.Count)
1429 {
1430 for (; (ulong)ptr2 % (ulong)(uint)Vector<byte>.Count != 0L; ptr2 += 4)
1431 {
1432 *(int*)ptr2 ^= num;
1433 }
1434 if (ptr3 - ptr2 >= Vector<byte>.Count)
1435 {
1436 Vector<byte> vector = Vector.AsVectorByte(new Vector<int>(num));
1437 do
1438 {
1439 *(Vector<byte>*)ptr2 ^= vector;
1440 ptr2 += Vector<byte>.Count;
1441 }
1442 while (ptr3 - ptr2 >= Vector<byte>.Count);
1443 }
1444 }
1445 for (; ptr3 - ptr2 >= 4; ptr2 += 4)
1446 {
1447 *(int*)ptr2 ^= num;
1448 }
1449 }
1450 while (ptr2 != ptr3)
1451 {
1452 byte* intPtr2 = ptr2++;
1453 *intPtr2 ^= ptr4[maskIndex];
1454 maskIndex = (maskIndex + 1) & 3;
1455 }
1456 }
1457 return maskIndex;
1458 }
static uint RotateLeft(uint value, int offset)
static bool IsHardwareAccelerated
Definition Vector.cs:14
int Length
Definition Span.cs:70

References System.Numerics.Vector< T >.Count, System.Numerics.Vector< T >.IsHardwareAccelerated, System.BitConverter.IsLittleEndian, System.L, System.Span< T >.Length, System.Numerics.BitOperations.RotateLeft(), and System.Numerics.BitOperations.RotateRight().