Skip to content

Commit 29d9d59

Browse files
crisbetommalerba
authored andcommitted
refactor(grid-list): remove unnecessary regex and cast to array (#2502)
* Removes a regex that can be replaced by a faster `indexOf` check. * Removes an unnecessary cast from a QueryList to an Array.
1 parent 727ce53 commit 29d9d59

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/lib/grid-list/grid-list.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class MdGridList implements OnInit, AfterContentChecked {
113113
private _setTileStyler(): void {
114114
if (this._rowHeight === MD_FIT_MODE) {
115115
this._tileStyler = new FitTileStyler();
116-
} else if (this._rowHeight && this._rowHeight.match(/:/g)) {
116+
} else if (this._rowHeight && this._rowHeight.indexOf(':') > -1) {
117117
this._tileStyler = new RatioTileStyler(this._rowHeight);
118118
} else {
119119
this._tileStyler = new FixedTileStyler(this._rowHeight);
@@ -122,16 +122,15 @@ export class MdGridList implements OnInit, AfterContentChecked {
122122

123123
/** Computes and applies the size and position for all children grid tiles. */
124124
private _layoutTiles(): void {
125-
let tiles = this._tiles.toArray();
126-
let tracker = new TileCoordinator(this.cols, tiles);
125+
let tracker = new TileCoordinator(this.cols, this._tiles);
127126
let direction = this._dir ? this._dir.value : 'ltr';
128127
this._tileStyler.init(this.gutterSize, tracker, this.cols, direction);
129128

130-
for (let i = 0; i < tiles.length; i++) {
131-
let pos = tracker.positions[i];
132-
let tile = tiles[i];
129+
this._tiles.forEach((tile, index) => {
130+
let pos = tracker.positions[index];
133131
this._tileStyler.setStyle(tile, pos.row, pos.col);
134-
}
132+
});
133+
135134
this._setListStyle(this._tileStyler.getComputedHeight());
136135
}
137136

src/lib/grid-list/tile-coordinator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {QueryList} from '@angular/core';
12
import {MdGridTile} from './grid-tile';
23
import {MdGridTileTooWideError} from './grid-list-errors';
34

@@ -43,7 +44,7 @@ export class TileCoordinator {
4344
/** The computed (row, col) position of each tile (the output). */
4445
positions: TilePosition[];
4546

46-
constructor(numColumns: number, tiles: MdGridTile[]) {
47+
constructor(numColumns: number, tiles: QueryList<MdGridTile>) {
4748
this.tracker = new Array(numColumns);
4849
this.tracker.fill(0, 0, this.tracker.length);
4950

0 commit comments

Comments
 (0)