Skip to content

Commit

Permalink
String serializer optimizations 2x performance
Browse files Browse the repository at this point in the history
  • Loading branch information
adam committed Jan 14, 2022
1 parent 68e718b commit a280612
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion HyperSerializer/HyperSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<DelaySign>true</DelaySign>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RepositoryUrl>https://github.com/Hyperlnq/HyperSerializer</RepositoryUrl>
<Version>1.0.9</Version>
<Version>1.0.10</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
Expand Down
4 changes: 2 additions & 2 deletions HyperSerializer/SnippetsSafe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ internal class SnippetsSafe : ISnippets
public string PropertyTemplateDeserializeLocal { get { return "var _{0} = ({1}) MemoryMarshal.Read<{1}>(bytes.Slice(offset+=offsetWritten, offsetWritten = {2}));"; } }
public string PropertyTemplateSerializeNullable { get { return "var _{0} = {1}?.{0} ?? default; offset+=offsetWritten; if(((bytes[offset++] = (byte)({1}?.{0}==null ? 1 : 0)) != 1)) MemoryMarshal.Write(bytes.Slice(offset, offsetWritten = {2}), ref _{0}); else offsetWritten = 0;"; } }
public string PropertyTemplateDeserializeNullable { get { return "offset+=offsetWritten; if(bytes[offset++] != 1) {0} = ({1}?) MemoryMarshal.Read<{1}>(bytes.Slice(offset, offsetWritten = {2})); else offsetWritten = 0;"; } }
public string PropertyTemplateSerializeVarLenStr { get { return "if(_{1} > 0) Utf8Encoding.GetBytes({0}.AsSpan(),bytes.Slice(offset+=offsetWritten, offsetWritten = _{1}));"; } }
public string PropertyTemplateDeserializeVarLenStr { get { return "{0} = (_{1} >= 0) ? Utf8Encoding.GetString(bytes.Slice(offset += offsetWritten, offsetWritten = _{1})) : null;"; } }
public string PropertyTemplateSerializeVarLenStr { get { return "if(_{1} > 0) MemoryMarshal.AsBytes({0}.AsSpan(),bytes.Slice(offset+=offsetWritten, offsetWritten = _{1}));"; } }
public string PropertyTemplateDeserializeVarLenStr { get { return "{0} = (_{1} >= 0) ? MemoryMarshal.Cast<byte,char>(bytes.Slice(offset += offsetWritten, offsetWritten = _{1})).ToString() : null;"; } }
public string StringLength { get { return "({0}?.Length ?? -1)"; } }
public string StringLengthSpan { get { return "({0}?.Length ?? 0)"; } }
public string ClassTemplate { get { return @"
Expand Down

0 comments on commit a280612

Please sign in to comment.