Skip to content

Commit

Permalink
Merge pull request #105 from sveinungf/dev/1.20.0
Browse files Browse the repository at this point in the history
Version 1.20.0
  • Loading branch information
sveinungf authored Feb 8, 2025
2 parents 8343da7 + 476f634 commit ca2d1ec
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 34 deletions.
4 changes: 2 additions & 2 deletions SpreadCheetah.Test/Tests/SpreadsheetRowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Spreadsheet_AddRow_ThrowsWhenNoWorksheet(bool hasWorksheet)
await spreadsheet.StartWorksheetAsync("Sheet");

// Act
var exception = await Record.ExceptionAsync(async () => await spreadsheet.AddRowAsync(Array.Empty<DataCell>()));
var exception = await Record.ExceptionAsync(async () => await spreadsheet.AddRowAsync([]));

// Assert
Assert.NotEqual(hasWorksheet, exception is SpreadCheetahException);
Expand All @@ -46,7 +46,7 @@ public async Task Spreadsheet_AddRow_ThrowsWhenAlreadyFinished(bool finished)
await spreadsheet.FinishAsync();

// Act
var exception = await Record.ExceptionAsync(async () => await spreadsheet.AddRowAsync(Array.Empty<DataCell>()));
var exception = await Record.ExceptionAsync(async () => await spreadsheet.AddRowAsync([]));

// Assert
Assert.Equal(finished, exception != null);
Expand Down
11 changes: 0 additions & 11 deletions SpreadCheetah/Helpers/HeaderNameExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,4 @@ public static void CopyToCells(
cells[i] = new StyledCell(headerNames[i], styleId);
}
}

public static void CopyToCells(
this IList<string> headerNames,
StyledCell[] cells,
StyleId? styleId)
{
for (var i = 0; i < headerNames.Count; ++i)
{
cells[i] = new StyledCell(headerNames[i], styleId);
}
}
}
6 changes: 3 additions & 3 deletions SpreadCheetah/SourceGeneration/EmptyWorksheetRowContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public static class EmptyWorksheetRowContext

private static ValueTask AddHeaderRowAsync(Spreadsheet spreadsheet, StyleId? _, CancellationToken token)
{
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);
return spreadsheet.AddRowAsync([], token);
}

private static ValueTask AddAsRowAsync<T>(Spreadsheet spreadsheet, T _, CancellationToken token)
{
ArgumentNullException.ThrowIfNull(spreadsheet);
return spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token);
return spreadsheet.AddRowAsync([], token);
}

private static ValueTask AddRangeAsRowsAsync<T>(Spreadsheet spreadsheet, IEnumerable<T> objs, CancellationToken token)
Expand All @@ -40,7 +40,7 @@ private static async ValueTask AddRangeAsEmptyRowsAsync<T>(Spreadsheet spreadshe
{
foreach (var _ in objs)
{
await spreadsheet.AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token).ConfigureAwait(false);
await spreadsheet.AddRowAsync([], token).ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion SpreadCheetah/SpreadCheetah.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- NuGet package -->
<PackageId>SpreadCheetah</PackageId>
<Version>1.19.0</Version>
<Version>1.20.0</Version>
<Authors>sveinungf</Authors>
<Description>SpreadCheetah is a high-performance .NET library for generating spreadsheet (Microsoft Excel XLSX) files.</Description>
<PackageIcon>icon-package.png</PackageIcon>
Expand Down
20 changes: 3 additions & 17 deletions SpreadCheetah/Spreadsheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public async ValueTask AddHeaderRowAsync(ReadOnlyMemory<string> headerNames, Sty
{
if (headerNames.Length == 0)
{
await AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token).ConfigureAwait(false);
await AddRowAsync([], token).ConfigureAwait(false);
return;
}

Expand All @@ -373,22 +373,8 @@ public async ValueTask AddHeaderRowAsync(ReadOnlyMemory<string> headerNames, Sty
public async ValueTask AddHeaderRowAsync(IList<string> headerNames, StyleId? styleId = null, CancellationToken token = default)
{
ArgumentNullException.ThrowIfNull(headerNames);
if (headerNames.Count == 0)
{
await AddRowAsync(ReadOnlyMemory<DataCell>.Empty, token).ConfigureAwait(false);
return;
}

var cells = ArrayPool<StyledCell>.Shared.Rent(headerNames.Count);
try
{
headerNames.CopyToCells(cells, styleId);
await AddRowAsync(cells.AsMemory(0, headerNames.Count), token).ConfigureAwait(false);
}
finally
{
ArrayPool<StyledCell>.Shared.Return(cells);
}
using var pooledArray = headerNames.ToPooledArray();
await AddHeaderRowAsync(pooledArray.Memory, styleId, token).ConfigureAwait(false);
}

/// <summary>
Expand Down

0 comments on commit ca2d1ec

Please sign in to comment.