iconGrid: Save class variables to local ones
It's quite slow to access class variables in JS, especially when they're backed by GObject properties. To avoid accessing them in every iteration when we're looping through the children of iconGrid, store those values to another variable and reuse that inside the loop. This shaves off another 0.2 ms from iconGrids vfunc_allocate(), getting the average time spent in that function down from 1.3 ms to 1.1 ms. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
This commit is contained in:
parent
7a5650d868
commit
7771bf4437
@ -662,9 +662,9 @@ var IconGridLayout = GObject.registerClass({
|
|||||||
return [leftEmptySpace, topEmptySpace, hSpacing, vSpacing];
|
return [leftEmptySpace, topEmptySpace, hSpacing, vSpacing];
|
||||||
}
|
}
|
||||||
|
|
||||||
_getRowPadding(items, itemIndex, childSize, spacing) {
|
_getRowPadding(align, items, itemIndex, childSize, spacing) {
|
||||||
if (this.lastRowAlign === Clutter.ActorAlign.START ||
|
if (align === Clutter.ActorAlign.START ||
|
||||||
this.lastRowAlign === Clutter.ActorAlign.FILL)
|
align === Clutter.ActorAlign.FILL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const nRows = Math.ceil(items.length / this.columnsPerPage);
|
const nRows = Math.ceil(items.length / this.columnsPerPage);
|
||||||
@ -685,7 +685,7 @@ var IconGridLayout = GObject.registerClass({
|
|||||||
const isRtl =
|
const isRtl =
|
||||||
Clutter.get_default_text_direction() === Clutter.TextDirection.RTL;
|
Clutter.get_default_text_direction() === Clutter.TextDirection.RTL;
|
||||||
|
|
||||||
switch (this.lastRowAlign) {
|
switch (align) {
|
||||||
case Clutter.ActorAlign.CENTER:
|
case Clutter.ActorAlign.CENTER:
|
||||||
rowAlign = availableWidth / 2;
|
rowAlign = availableWidth / 2;
|
||||||
break;
|
break;
|
||||||
@ -784,32 +784,38 @@ var IconGridLayout = GObject.registerClass({
|
|||||||
const childBox = new Clutter.ActorBox();
|
const childBox = new Clutter.ActorBox();
|
||||||
|
|
||||||
let nChangedIcons = 0;
|
let nChangedIcons = 0;
|
||||||
|
const columnsPerPage = this.columnsPerPage;
|
||||||
|
const orientation = this._orientation;
|
||||||
|
const pageWidth = this._pageWidth;
|
||||||
|
const pageHeight = this._pageHeight;
|
||||||
|
const pageSizeChanged = this._pageSizeChanged;
|
||||||
|
const lastRowAlign = this.lastRowAlign;
|
||||||
|
|
||||||
this._pages.forEach((page, pageIndex) => {
|
this._pages.forEach((page, pageIndex) => {
|
||||||
if (isRtl && this._orientation === Clutter.Orientation.HORIZONTAL)
|
if (isRtl && orientation === Clutter.Orientation.HORIZONTAL)
|
||||||
pageIndex = swap(pageIndex, this._pages.length);
|
pageIndex = swap(pageIndex, this._pages.length);
|
||||||
|
|
||||||
page.visibleChildren.forEach((item, itemIndex) => {
|
page.visibleChildren.forEach((item, itemIndex) => {
|
||||||
const row = Math.floor(itemIndex / this.columnsPerPage);
|
const row = Math.floor(itemIndex / columnsPerPage);
|
||||||
let column = itemIndex % this.columnsPerPage;
|
let column = itemIndex % columnsPerPage;
|
||||||
|
|
||||||
if (isRtl)
|
if (isRtl)
|
||||||
column = swap(column, this.columnsPerPage);
|
column = swap(column, columnsPerPage);
|
||||||
|
|
||||||
const rowPadding = this._getRowPadding(page.visibleChildren,
|
const rowPadding = this._getRowPadding(lastRowAlign,
|
||||||
itemIndex, childSize, hSpacing);
|
page.visibleChildren, itemIndex, childSize, hSpacing);
|
||||||
|
|
||||||
// Icon position
|
// Icon position
|
||||||
let x = leftEmptySpace + rowPadding + column * (childSize + hSpacing);
|
let x = leftEmptySpace + rowPadding + column * (childSize + hSpacing);
|
||||||
let y = topEmptySpace + row * (childSize + vSpacing);
|
let y = topEmptySpace + row * (childSize + vSpacing);
|
||||||
|
|
||||||
// Page start
|
// Page start
|
||||||
switch (this._orientation) {
|
switch (orientation) {
|
||||||
case Clutter.Orientation.HORIZONTAL:
|
case Clutter.Orientation.HORIZONTAL:
|
||||||
x += pageIndex * this._pageWidth;
|
x += pageIndex * pageWidth;
|
||||||
break;
|
break;
|
||||||
case Clutter.Orientation.VERTICAL:
|
case Clutter.Orientation.VERTICAL:
|
||||||
y += pageIndex * this._pageHeight;
|
y += pageIndex * pageHeight;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,7 +827,7 @@ var IconGridLayout = GObject.registerClass({
|
|||||||
Math.max(childSize, naturalHeight));
|
Math.max(childSize, naturalHeight));
|
||||||
|
|
||||||
// Only ease icons when the page size didn't change
|
// Only ease icons when the page size didn't change
|
||||||
if (this._pageSizeChanged)
|
if (pageSizeChanged)
|
||||||
item.allocate(childBox);
|
item.allocate(childBox);
|
||||||
else if (animateIconPosition(item, childBox, nChangedIcons))
|
else if (animateIconPosition(item, childBox, nChangedIcons))
|
||||||
nChangedIcons++;
|
nChangedIcons++;
|
||||||
|
Loading…
Reference in New Issue
Block a user