ForeverZer0 / SharpNBT

A pure CLS-compliant C# implementation of the Named Binary Tag (NBT) format specification commonly used with Minecraft applications, allowing easy reading/writing streams and serialization to other formats.
MIT License
25 stars 9 forks source link

Optimize TagReader/TagWriter #21

Open ForeverZer0 opened 10 months ago

ForeverZer0 commented 10 months ago

The TagReader and TagWriter class still use the naive and legacy method of BitConverter.GetBytes paired with Array.Reverse to get the correct byte-order.

Replace all these method calls with the use of stackalloc spans and employ BinaryPrimitives methods to read/write in the appropriate endian. This will make them free of any heap-allocations in additional to being computationally less expensive.