From 275a452bd0f6e928cd8d8a9a8ac475cfb1ed344b Mon Sep 17 00:00:00 2001 From: Blake LaFleur Date: Sun, 11 Aug 2024 22:19:07 -0500 Subject: [PATCH] Micro optimization and package updates --- .../Fragment.NetSlum.Core.csproj | 4 ++-- .../Objects/FragmentMessage.cs | 15 +++++++-------- ...blshRequest.cs => AreaServerPublishRequest.cs} | 6 +++--- .../Fragment.NetSlum.Server.csproj | 12 ++++++------ .../Fragment.NetSlum.TcpServer.csproj | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) rename src/Fragment.NetSlum.Networking/Packets/Request/AreaServer/{AreaServerPublshRequest.cs => AreaServerPublishRequest.cs} (81%) diff --git a/src/Fragment.NetSlum.Core/Fragment.NetSlum.Core.csproj b/src/Fragment.NetSlum.Core/Fragment.NetSlum.Core.csproj index c524f2b..76c08a5 100644 --- a/src/Fragment.NetSlum.Core/Fragment.NetSlum.Core.csproj +++ b/src/Fragment.NetSlum.Core/Fragment.NetSlum.Core.csproj @@ -13,11 +13,11 @@ IPNetwork2 - + - + diff --git a/src/Fragment.NetSlum.Networking/Objects/FragmentMessage.cs b/src/Fragment.NetSlum.Networking/Objects/FragmentMessage.cs index aa2119e..006c64b 100644 --- a/src/Fragment.NetSlum.Networking/Objects/FragmentMessage.cs +++ b/src/Fragment.NetSlum.Networking/Objects/FragmentMessage.cs @@ -24,13 +24,12 @@ public class FragmentMessage public byte[] ToArray() { + var length = sizeof(ushort) + Length; + var buffer = length <= 8192 ? stackalloc byte[length] : new byte[length]; + const int dataOffset = 4; - var buffer = new byte[sizeof(ushort) + Length]; - var span = new Span(buffer); - var dataOffset = 4; - - BinaryPrimitives.WriteUInt16BigEndian(span[..2], Length); - BinaryPrimitives.WriteUInt16BigEndian(span[2..4], (ushort)MessageType); + BinaryPrimitives.WriteUInt16BigEndian(buffer[..2], Length); + BinaryPrimitives.WriteUInt16BigEndian(buffer[2..4], (ushort)MessageType); // If the data of this message is already encrypted, it is assumed that the checksum was already appended since it needs to be // included in the encrypted payload @@ -40,9 +39,9 @@ public byte[] ToArray() //dataOffset += 2; } - Data.Span.CopyTo(span[dataOffset..]); + Data.Span.CopyTo(buffer[dataOffset..]); - return buffer; + return buffer.ToArray(); } public override string ToString() diff --git a/src/Fragment.NetSlum.Networking/Packets/Request/AreaServer/AreaServerPublshRequest.cs b/src/Fragment.NetSlum.Networking/Packets/Request/AreaServer/AreaServerPublishRequest.cs similarity index 81% rename from src/Fragment.NetSlum.Networking/Packets/Request/AreaServer/AreaServerPublshRequest.cs rename to src/Fragment.NetSlum.Networking/Packets/Request/AreaServer/AreaServerPublishRequest.cs index 17648c7..d35969e 100644 --- a/src/Fragment.NetSlum.Networking/Packets/Request/AreaServer/AreaServerPublshRequest.cs +++ b/src/Fragment.NetSlum.Networking/Packets/Request/AreaServer/AreaServerPublishRequest.cs @@ -11,11 +11,11 @@ namespace Fragment.NetSlum.Networking.Packets.Request.AreaServer; [FragmentPacket(MessageType.Data, OpCodes.Data_AreaServerPublishRequest)] -public class AreaServerPublshRequest :BaseRequest +public class AreaServerPublishRequest :BaseRequest { - private readonly ILogger _logger; + private readonly ILogger _logger; - public AreaServerPublshRequest(ILogger logger) + public AreaServerPublishRequest(ILogger logger) { _logger = logger; } diff --git a/src/Fragment.NetSlum.Server/Fragment.NetSlum.Server.csproj b/src/Fragment.NetSlum.Server/Fragment.NetSlum.Server.csproj index 61d47af..a820ded 100644 --- a/src/Fragment.NetSlum.Server/Fragment.NetSlum.Server.csproj +++ b/src/Fragment.NetSlum.Server/Fragment.NetSlum.Server.csproj @@ -12,25 +12,25 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + - - + + diff --git a/src/Fragment.NetSlum.TcpServer/Fragment.NetSlum.TcpServer.csproj b/src/Fragment.NetSlum.TcpServer/Fragment.NetSlum.TcpServer.csproj index ddd4470..9f70e9b 100644 --- a/src/Fragment.NetSlum.TcpServer/Fragment.NetSlum.TcpServer.csproj +++ b/src/Fragment.NetSlum.TcpServer/Fragment.NetSlum.TcpServer.csproj @@ -8,7 +8,7 @@ - +