From 7771bf4437d236f69121f458273743fe7d565b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Wed, 24 Feb 2021 12:07:03 +0100 Subject: [PATCH] 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: --- js/ui/iconGrid.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js index 8f6b54701..0fc37a49c 100644 --- a/js/ui/iconGrid.js +++ b/js/ui/iconGrid.js @@ -662,9 +662,9 @@ var IconGridLayout = GObject.registerClass({ return [leftEmptySpace, topEmptySpace, hSpacing, vSpacing]; } - _getRowPadding(items, itemIndex, childSize, spacing) { - if (this.lastRowAlign === Clutter.ActorAlign.START || - this.lastRowAlign === Clutter.ActorAlign.FILL) + _getRowPadding(align, items, itemIndex, childSize, spacing) { + if (align === Clutter.ActorAlign.START || + align === Clutter.ActorAlign.FILL) return 0; const nRows = Math.ceil(items.length / this.columnsPerPage); @@ -685,7 +685,7 @@ var IconGridLayout = GObject.registerClass({ const isRtl = Clutter.get_default_text_direction() === Clutter.TextDirection.RTL; - switch (this.lastRowAlign) { + switch (align) { case Clutter.ActorAlign.CENTER: rowAlign = availableWidth / 2; break; @@ -784,32 +784,38 @@ var IconGridLayout = GObject.registerClass({ const childBox = new Clutter.ActorBox(); 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) => { - if (isRtl && this._orientation === Clutter.Orientation.HORIZONTAL) + if (isRtl && orientation === Clutter.Orientation.HORIZONTAL) pageIndex = swap(pageIndex, this._pages.length); page.visibleChildren.forEach((item, itemIndex) => { - const row = Math.floor(itemIndex / this.columnsPerPage); - let column = itemIndex % this.columnsPerPage; + const row = Math.floor(itemIndex / columnsPerPage); + let column = itemIndex % columnsPerPage; if (isRtl) - column = swap(column, this.columnsPerPage); + column = swap(column, columnsPerPage); - const rowPadding = this._getRowPadding(page.visibleChildren, - itemIndex, childSize, hSpacing); + const rowPadding = this._getRowPadding(lastRowAlign, + page.visibleChildren, itemIndex, childSize, hSpacing); // Icon position let x = leftEmptySpace + rowPadding + column * (childSize + hSpacing); let y = topEmptySpace + row * (childSize + vSpacing); // Page start - switch (this._orientation) { + switch (orientation) { case Clutter.Orientation.HORIZONTAL: - x += pageIndex * this._pageWidth; + x += pageIndex * pageWidth; break; case Clutter.Orientation.VERTICAL: - y += pageIndex * this._pageHeight; + y += pageIndex * pageHeight; break; } @@ -821,7 +827,7 @@ var IconGridLayout = GObject.registerClass({ Math.max(childSize, naturalHeight)); // Only ease icons when the page size didn't change - if (this._pageSizeChanged) + if (pageSizeChanged) item.allocate(childBox); else if (animateIconPosition(item, childBox, nChangedIcons)) nChangedIcons++;