Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try improve the column-width/row-height adjustment performance #487

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ReoGrid/Actions/SetColumnsWidthAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public override void Do()
int col = base.Range.Col;
int count = base.Range.Cols;

backupCols.Clear();
backupColsWidth.Clear();

int c2 = col + count;
for (int c = col; c < c2; c++)
{
ColumnHeader colHead = Worksheet.RetrieveColumnHeader(c);
backupCols.Add(c, colHead.InnerWidth);
backupColsWidth.Add(c, colHead.InnerWidth);
}

Worksheet.SetColumnsWidth(col, count, width);
}

private Dictionary<int, ushort> backupCols = new Dictionary<int, ushort>();
private Dictionary<int, ushort> backupColsWidth = new Dictionary<int, ushort>();

/// <summary>
/// Undo this action
Expand All @@ -73,7 +73,7 @@ public override void Undo()
int col = base.Range.Col;
int count = base.Range.Cols;

Worksheet.SetColumnsWidth(col, count, c => backupCols[c]);
Worksheet.SetColumnsWidth(col, count, c => backupColsWidth[c]);
}

/// <summary>
Expand Down
17 changes: 14 additions & 3 deletions ReoGrid/Core/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,21 @@ public bool AutoFitRowHeight(int row, bool byAction = false)
/// be done by performing action, that will be able to revoke this behavior.</param>
/// <returns>Return true if operation actually done; Return false if nothing
/// need to do (cells are default width).</returns>
public bool AutoFitColumnWidth(int col, bool byAction = false)
public bool AutoFitColumnsWidth(int col, int count, bool byAction = false)
{
if (col < 0 || col > this.cols.Count - 1)
{
throw new ArgumentOutOfRangeException("col");
throw new ArgumentOutOfRangeException(nameof(col));
}

if (count < 1)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

if (col + count > this.cols.Count)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

RGFloat maxWidth = 0;
Expand Down Expand Up @@ -3178,9 +3188,10 @@ private void VerifyWorksheet()
/// </summary>
/// <param name="byAction">Determines whether or not this operation
/// performed by doing action, which will provide the ability to undo this operation.</param>
[Obsolete("For a performance issue, consider use Worksheet.SetColumnsWidthAction instead")]
public void FitWidthToCells(bool byAction = false)
{
this.Worksheet.AutoFitColumnWidth(this.Col, byAction);
this.Worksheet.AutoFitColumnsWidth(this.Col, 1, byAction);
}

internal ColumnHeader Clone(Worksheet newSheet)
Expand Down
2 changes: 1 addition & 1 deletion ReoGrid/ReoGrid.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net40</TargetFrameworks>
<TargetFrameworks>;netcoreapp3.1</TargetFrameworks>
<OutputType>Library</OutputType>
<RootNamespace>unvell.ReoGrid</RootNamespace>
<AssemblyName>unvell.ReoGrid</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion ReoGrid/Views/Header/ColumnHeaderView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public override bool OnMouseDoubleClick(Point location, MouseButtons buttons)
&& buttons == MouseButtons.Left
&& this.sheet.HasSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth))
{
this.sheet.AutoFitColumnWidth(col, byAction: true);
this.sheet.AutoFitColumnsWidth(col, 1, byAction: true);

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion TestCase/TestCase.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" />
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>unvell.ReoGrid.Tests</RootNamespace>
<AssemblyName>ReoGridUnitTest</AssemblyName>
Expand Down Expand Up @@ -31,6 +31,7 @@
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineConstants>TRACE;EX_SCRIPT</DefineConstants>
Expand Down