From 4ba7686eb79a06b7165c007b41cd0cf7bb3ddb2d Mon Sep 17 00:00:00 2001 From: mtklein Date: Thu, 16 Oct 2014 09:23:21 -0700 Subject: [PATCH] Tweak out SkTileGrid::insert() loop. BUG=skia: Review URL: https://codereview.chromium.org/658913002 --- src/core/SkTileGrid.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/SkTileGrid.cpp b/src/core/SkTileGrid.cpp index fd00253097..10782c4d6d 100644 --- a/src/core/SkTileGrid.cpp +++ b/src/core/SkTileGrid.cpp @@ -84,10 +84,15 @@ void SkTileGrid::insert(unsigned opIndex, const SkRect& originalBounds, bool) { SkIRect grid; this->userToGrid(bounds, &grid); - for (int y = grid.fTop; y <= grid.fBottom; y++) { - for (int x = grid.fLeft; x <= grid.fRight; x++) { - fTiles[y * fXTiles + x].push(opIndex); + // This is just a loop over y then x. This compiles to a slightly faster and + // more compact loop than if we just did fTiles[y * fXTiles + x].push(opIndex). + SkTDArray* row = &fTiles[grid.fTop * fXTiles + grid.fLeft]; + for (int y = 0; y <= grid.fBottom - grid.fTop; y++) { + SkTDArray* tile = row; + for (int x = 0; x <= grid.fRight - grid.fLeft; x++) { + (tile++)->push(opIndex); } + row += fXTiles; } }