-
Notifications
You must be signed in to change notification settings - Fork 241
[Mac] Cache cell width to improve size calculations #813
base: main
Are you sure you want to change the base?
Conversation
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)); |
There was a problem hiding this comment.
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>
)
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
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.