From a9e8a7ff0e993d946c719b0bea8735483f0e6a2d Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 17 Feb 2019 00:13:22 +0100 Subject: Speed up computeBounds --- board.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/board.cpp b/board.cpp index 91655dc..bd56f8a 100644 --- a/board.cpp +++ b/board.cpp @@ -160,15 +160,13 @@ const vector& Board::getEdgeCells() const { Bounds Board::computeBounds() const { Bounds bounds; - for (int y = 1; y < BSZ - 1; y++) { - for (int x = 1; x < BSZ - 1; x++) { - int idx = BSZ * y + x; - if (bd[idx] != 0 || checkEdge(idx)) { - bounds.left = min(bounds.left, x); - bounds.right = max(bounds.right, x); - bounds.top = min(bounds.top, y); - bounds.bottom = max(bounds.bottom, y); - } + for (int idx : edgeCells) { + int x = idx % BSZ, y = idx / BSZ; + if (bd[idx] != 0 || checkEdge(idx)) { + bounds.left = min(bounds.left, x); + bounds.right = max(bounds.right, x); + bounds.top = min(bounds.top, y); + bounds.bottom = max(bounds.bottom, y); } } -- cgit v1.2.3