mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
perf: CompressVarInt uses WriteByte instead of Write<T> to avoid Action call overhead
This commit is contained in:
parent
a868368eca
commit
5fcbd1d550
@ -201,84 +201,84 @@ public static void CompressVarUInt(NetworkWriter writer, ulong value)
|
||||
{
|
||||
if (value <= 240)
|
||||
{
|
||||
writer.Write((byte)value);
|
||||
writer.WriteByte((byte)value);
|
||||
return;
|
||||
}
|
||||
if (value <= 2287)
|
||||
{
|
||||
writer.Write((byte)(((value - 240) >> 8) + 241));
|
||||
writer.Write((byte)((value - 240) & 0xFF));
|
||||
writer.WriteByte((byte)(((value - 240) >> 8) + 241));
|
||||
writer.WriteByte((byte)((value - 240) & 0xFF));
|
||||
return;
|
||||
}
|
||||
if (value <= 67823)
|
||||
{
|
||||
writer.Write((byte)249);
|
||||
writer.Write((byte)((value - 2288) >> 8));
|
||||
writer.Write((byte)((value - 2288) & 0xFF));
|
||||
writer.WriteByte((byte)249);
|
||||
writer.WriteByte((byte)((value - 2288) >> 8));
|
||||
writer.WriteByte((byte)((value - 2288) & 0xFF));
|
||||
return;
|
||||
}
|
||||
if (value <= 16777215)
|
||||
{
|
||||
writer.Write((byte)250);
|
||||
writer.Write((byte)(value & 0xFF));
|
||||
writer.Write((byte)((value >> 8) & 0xFF));
|
||||
writer.Write((byte)((value >> 16) & 0xFF));
|
||||
writer.WriteByte((byte)250);
|
||||
writer.WriteByte((byte)(value & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 8) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 16) & 0xFF));
|
||||
return;
|
||||
}
|
||||
if (value <= 4294967295)
|
||||
{
|
||||
writer.Write((byte)251);
|
||||
writer.Write((byte)(value & 0xFF));
|
||||
writer.Write((byte)((value >> 8) & 0xFF));
|
||||
writer.Write((byte)((value >> 16) & 0xFF));
|
||||
writer.Write((byte)((value >> 24) & 0xFF));
|
||||
writer.WriteByte((byte)251);
|
||||
writer.WriteByte((byte)(value & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 8) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 16) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 24) & 0xFF));
|
||||
return;
|
||||
}
|
||||
if (value <= 1099511627775)
|
||||
{
|
||||
writer.Write((byte)252);
|
||||
writer.Write((byte)(value & 0xFF));
|
||||
writer.Write((byte)((value >> 8) & 0xFF));
|
||||
writer.Write((byte)((value >> 16) & 0xFF));
|
||||
writer.Write((byte)((value >> 24) & 0xFF));
|
||||
writer.Write((byte)((value >> 32) & 0xFF));
|
||||
writer.WriteByte((byte)252);
|
||||
writer.WriteByte((byte)(value & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 8) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 16) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 24) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 32) & 0xFF));
|
||||
return;
|
||||
}
|
||||
if (value <= 281474976710655)
|
||||
{
|
||||
writer.Write((byte)253);
|
||||
writer.Write((byte)(value & 0xFF));
|
||||
writer.Write((byte)((value >> 8) & 0xFF));
|
||||
writer.Write((byte)((value >> 16) & 0xFF));
|
||||
writer.Write((byte)((value >> 24) & 0xFF));
|
||||
writer.Write((byte)((value >> 32) & 0xFF));
|
||||
writer.Write((byte)((value >> 40) & 0xFF));
|
||||
writer.WriteByte((byte)253);
|
||||
writer.WriteByte((byte)(value & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 8) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 16) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 24) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 32) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 40) & 0xFF));
|
||||
return;
|
||||
}
|
||||
if (value <= 72057594037927935)
|
||||
{
|
||||
writer.Write((byte)254);
|
||||
writer.Write((byte)(value & 0xFF));
|
||||
writer.Write((byte)((value >> 8) & 0xFF));
|
||||
writer.Write((byte)((value >> 16) & 0xFF));
|
||||
writer.Write((byte)((value >> 24) & 0xFF));
|
||||
writer.Write((byte)((value >> 32) & 0xFF));
|
||||
writer.Write((byte)((value >> 40) & 0xFF));
|
||||
writer.Write((byte)((value >> 48) & 0xFF));
|
||||
writer.WriteByte((byte)254);
|
||||
writer.WriteByte((byte)(value & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 8) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 16) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 24) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 32) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 40) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 48) & 0xFF));
|
||||
return;
|
||||
}
|
||||
|
||||
// all others
|
||||
{
|
||||
writer.Write((byte)255);
|
||||
writer.Write((byte)(value & 0xFF));
|
||||
writer.Write((byte)((value >> 8) & 0xFF));
|
||||
writer.Write((byte)((value >> 16) & 0xFF));
|
||||
writer.Write((byte)((value >> 24) & 0xFF));
|
||||
writer.Write((byte)((value >> 32) & 0xFF));
|
||||
writer.Write((byte)((value >> 40) & 0xFF));
|
||||
writer.Write((byte)((value >> 48) & 0xFF));
|
||||
writer.Write((byte)((value >> 56) & 0xFF));
|
||||
writer.WriteByte((byte)255);
|
||||
writer.WriteByte((byte)(value & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 8) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 16) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 24) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 32) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 40) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 48) & 0xFF));
|
||||
writer.WriteByte((byte)((value >> 56) & 0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user