summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-02-17 00:13:22 +0100
committertomsmeding <tom.smeding@gmail.com>2019-02-17 00:13:22 +0100
commita9e8a7ff0e993d946c719b0bea8735483f0e6a2d (patch)
treeffdceb3ad119d206ba1453d63ee9adb872c0f648
parentfa4483dc336deafea36768e1e8a804e9d0ae823d (diff)
Speed up computeBounds
-rw-r--r--board.cpp16
1 files 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<int>& 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);
}
}