Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

[Mac] Cache cell width to improve size calculations #813

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sevoku
Copy link
Member

@sevoku sevoku commented Mar 20, 2018

By caching the widths required to render each CompositeCell, the amount of required size calculations is reduced drastically. This also reduces the amount of drawing cycles and improves the overall speed and responsivness of lists/trees a lot.

Limitation: this adds caching only, but full cell resize is still not supported. A call to QueueResize will remeasure the cell and update the height required to render the cell with its current width. For a full resize we'll need to hook the column autosizing into the resizing process.

By caching the widths required to render each CompositeCell,
the amount of required size calculations is reduced
drastically. This also reduces the amount of drawing cycles
and improves the overall speed and responsivness of lists/trees
a lot.
NSTableColumn tcol = base.AddColumn (col);
var widths = new List<nfloat> ();
if (Table.RowCount > 0)
widths.InsertRange (0, Enumerable.Repeat<nfloat> (-1f, (int)Table.RowCount));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will do Insert N times instead of doing a block insert. Avoid direct IEnumerables here. Please pass something ICollection derived. (the IEnumerable<T> overload handles checking for ICollection<T>)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think pre-allocating list capacity (new List<nfloat> (table.RowCount) then doing
for (int i = 0; i < Table.RowCount; ++i) widths.Add (-1f) is better

public virtual void SetSource (IListDataSource source, IBackend sourceBackend)
{
this.source = source;

RowHeights = new List<nfloat> ();
for (int i = 0; i < source.RowCount; i++)
RowHeights.Add (-1);
foreach (var colWidths in ColumnRowWidths) {
colWidths.Clear ();
colWidths.AddRange (Enumerable.Repeat<nfloat> (-1, source.RowCount));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, AddRange on IEnumerable<T> but not ICollection<T> does not do block copy.

Base automatically changed from master to main March 9, 2021 14:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants