Skip to content

Commit cb09846

Browse files
committed
Replace usage of ArrayPool, remove dependency System.Buffers
1 parent b1d9932 commit cb09846

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

Ical.Net/Ical.Net.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'">
1212
<PackageReference Include="Portable.System.DateTimeOnly" Version="8.0.1" />
1313
</ItemGroup>
14-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
15-
<PackageReference Include="System.Buffers" Version="4.6.0" />
16-
</ItemGroup>
1714
<ItemGroup>
1815
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
1916
<_Parameter1>Ical.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a1f790f70176d52efbd248577bdb292be2d0acc62f3227c523e267d64767f207f81536c77bb91d17031a5afbc2d69cd3b5b3b9c98fa8df2cd363ec90a08639a1213ad70079eff666bcc14cf6574b899f4ad0eac672c8f763291cb1e0a2304d371053158cb398b2e6f9eeb45db7d1b4d2bbba1f985676c5ca4602fab3671d34bf</_Parameter1>

Ical.Net/Utility/TextUtil.cs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//
55

66
using System;
7-
using System.Buffers;
87
using System.Collections.Generic;
98
using System.IO;
109
using System.Text;
@@ -30,47 +29,38 @@ public static void FoldLines(this StringBuilder result, string inputLine)
3029

3130
// Use ArrayPool<char> to rent arrays for processing
3231
// Cannot use Span<char> and stackalloc because netstandard2.0 does not support it
33-
var arrayPool = ArrayPool<char>.Shared;
34-
var currentLineArray = arrayPool.Rent(76); // 75 characters + 1 space
32+
var currentLineArray = new char[76]; // 75 characters + 1 space
3533

36-
try
37-
{
38-
var currentLineIndex = 0;
39-
var byteCount = 0;
40-
var charCount = 0;
41-
42-
while (charCount < inputLine.Length)
43-
{
44-
var currentCharByteCount = Encoding.UTF8.GetByteCount([inputLine[charCount]]);
34+
var currentLineIndex = 0;
35+
var byteCount = 0;
36+
var charCount = 0;
4537

46-
if (byteCount + currentCharByteCount > 75)
47-
{
48-
result.Append(currentLineArray, 0, currentLineIndex);
49-
result.Append(SerializationConstants.LineBreak);
50-
51-
currentLineIndex = 0;
52-
byteCount = 1;
53-
currentLineArray[currentLineIndex++] = ' ';
54-
}
55-
56-
currentLineArray[currentLineIndex++] = inputLine[charCount];
57-
byteCount += currentCharByteCount;
58-
charCount++;
59-
}
38+
while (charCount < inputLine.Length)
39+
{
40+
var currentCharByteCount = Encoding.UTF8.GetByteCount([inputLine[charCount]]);
6041

61-
// Append the remaining characters to the result
62-
if (currentLineIndex > 0)
42+
if (byteCount + currentCharByteCount > 75)
6343
{
6444
result.Append(currentLineArray, 0, currentLineIndex);
45+
result.Append(SerializationConstants.LineBreak);
46+
47+
currentLineIndex = 0;
48+
byteCount = 1;
49+
currentLineArray[currentLineIndex++] = ' ';
6550
}
6651

67-
result.Append(SerializationConstants.LineBreak);
52+
currentLineArray[currentLineIndex++] = inputLine[charCount];
53+
byteCount += currentCharByteCount;
54+
charCount++;
6855
}
69-
finally
56+
57+
// Append the remaining characters to the result
58+
if (currentLineIndex > 0)
7059
{
71-
// Return the rented array to the pool
72-
arrayPool.Return(currentLineArray);
60+
result.Append(currentLineArray, 0, currentLineIndex);
7361
}
62+
63+
result.Append(SerializationConstants.LineBreak);
7464
}
7565

7666
public static IEnumerable<string> Chunk(string str, int chunkSize = 73)

0 commit comments

Comments
 (0)