Skip to content

Commit b0cfcd5

Browse files
authored
refactor: use Encoding.Preamble to reduce array creation (#183)
only on .NET Core 2.1 or higher
1 parent 95365d7 commit b0cfcd5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Nogic.WritableOptions/JsonWritableOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ public void Update(TOptions changedValue, bool reload = false)
100100
ReadOnlySpan<byte> utf8Json = buffer.AsSpan();
101101

102102
// Check BOM
103+
#if NETCOREAPP2_1_OR_GREATER
104+
var utf8bom = Encoding.UTF8.Preamble;
105+
#else
103106
ReadOnlySpan<byte> utf8bom = Encoding.UTF8.GetPreamble();
107+
#endif
104108
if (utf8Json.StartsWith(utf8bom))
105109
{
106110
#pragma warning disable IDE0057

0 commit comments

Comments
 (0)