Skip to content

Commit 09f9dfd

Browse files
author
Andrii Bondarchuk
committed
use ArrayBufferWriter<byte>
1 parent 344955f commit 09f9dfd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/FitSyncHub.Functions/Functions/EverestingHOFScraperHttpTriggerFunction.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text;
1+
using System.Buffers;
2+
using System.Text;
23
using System.Text.Json;
34
using System.Text.RegularExpressions;
45
using HtmlAgilityPack;
@@ -181,29 +182,28 @@ private static IEnumerable<string> GetScriptParts(string html)
181182

182183
private static JsonElement ParseActivitiesJsonFromFullScript(IEnumerable<string> scripts)
183184
{
185+
var writer = new ArrayBufferWriter<byte>();
184186
const string StartPattern = "12:[\"$\",\"$L1c\",null,";
185-
byte[]? data = default;
186187

187188
foreach (var script in scripts)
188189
{
189-
if (data is null)
190+
if (writer.WrittenCount == 0)
190191
{
191192
var idx = script.IndexOf(StartPattern);
192193
if (idx < 0)
193194
{
194195
continue;
195196
}
196197

197-
data = Encoding.UTF8.GetBytes(script[(idx + StartPattern.Length)..]);
198-
198+
writer.Write(Encoding.UTF8.GetBytes(script[(idx + StartPattern.Length)..]));
199199
}
200200
else
201201
{
202-
data = [.. data, .. Encoding.UTF8.GetBytes(script)];
202+
writer.Write(Encoding.UTF8.GetBytes(script));
203203
}
204204

205205
//isFinalBlock: false to avoid exception throwing
206-
var reader = new Utf8JsonReader(data, isFinalBlock: false, new());
206+
var reader = new Utf8JsonReader(writer.WrittenSpan, isFinalBlock: false, new());
207207
if (JsonDocument.TryParseValue(ref reader, out var document))
208208
{
209209
return document.RootElement;

0 commit comments

Comments
 (0)