Skip to content

Commit 9649b96

Browse files
committed
feat: Use String.Create() in ToLegacyFormat() for Project
1 parent fa5cebf commit 9649b96

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

src/GettingThingsDone.ApplicationCore/Services/LegacyExchangeActionFormat.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Buffers;
32
using System.Globalization;
43
using GettingThingsDone.Contracts.Dto;
54
using GettingThingsDone.Contracts.Interface;

src/GettingThingsDone.ApplicationCore/Services/LegacyExchangeActionListFormat.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Buffers;
32
using GettingThingsDone.Contracts.Dto;
43
using GettingThingsDone.Contracts.Interface;
54
using GettingThingsDone.Contracts.Model;

src/GettingThingsDone.ApplicationCore/Services/LegacyExchangeProjectFormat.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Buffers;
32
using GettingThingsDone.Contracts.Dto;
43
using GettingThingsDone.Contracts.Interface;
54
using GettingThingsDone.Contracts.Model;
@@ -37,23 +36,14 @@ public static ServiceResult<ProjectDto> ToProjectDto(string legacyExchangeValue)
3736

3837
public static string ToLegacyFormat(this Project project)
3938
{
40-
var buffer = ArrayPool<char>.Shared.Rent(TotalWidth);
41-
42-
string result;
43-
try
39+
return string.Create(TotalWidth, project, (span, state) =>
4440
{
45-
Array.Fill(buffer, ' ');
46-
47-
project.Name?.CopyTo(0, buffer, TitleStart, Math.Min(TitleWidth, project.Name.Length));
41+
span.Fill(' ');
4842

49-
result = new string(buffer);
50-
}
51-
finally
52-
{
53-
ArrayPool<char>.Shared.Return(buffer);
54-
}
43+
var titleSpan = span.Slice(TitleStart, TitleWidth);
5544

56-
return result;
45+
state.Name?.AsSpan(0, Math.Min(TitleWidth, state.Name.Length)).CopyTo(titleSpan);
46+
});
5747
}
5848
}
5949
}

0 commit comments

Comments
 (0)