Skip to content

Commit

Permalink
refactor: use Encoding.Preamble to reduce array creation (#183)
Browse files Browse the repository at this point in the history
only on .NET Core 2.1 or higher
  • Loading branch information
nogic1008 authored Jan 19, 2023
1 parent 95365d7 commit b0cfcd5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Nogic.WritableOptions/JsonWritableOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ public void Update(TOptions changedValue, bool reload = false)
ReadOnlySpan<byte> utf8Json = buffer.AsSpan();

// Check BOM
#if NETCOREAPP2_1_OR_GREATER
var utf8bom = Encoding.UTF8.Preamble;
#else
ReadOnlySpan<byte> utf8bom = Encoding.UTF8.GetPreamble();
#endif
if (utf8Json.StartsWith(utf8bom))
{
#pragma warning disable IDE0057
Expand Down

0 comments on commit b0cfcd5

Please sign in to comment.