Skip to content

Commit 904df7c

Browse files
committed
small optimization
1 parent cc630dc commit 904df7c

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,17 @@ function hasManySiblings(img, x1, y1, width, height) {
183183
const y0 = Math.max(y1 - 1, 0);
184184
const x2 = Math.min(x1 + 1, width - 1);
185185
const y2 = Math.min(y1 + 1, height - 1);
186-
const pos = y1 * width + x1;
186+
const val = img[y1 * width + x1];
187187
let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
188188

189189
// go through 8 adjacent pixels
190190
for (let x = x0; x <= x2; x++) {
191191
for (let y = y0; y <= y2; y++) {
192192
if (x === x1 && y === y1) continue;
193-
if (img[pos] === img[y * width + x]) zeroes++;
193+
zeroes += +(val === img[y * width + x]);
194194
if (zeroes > 2) return true;
195195
}
196196
}
197-
198197
return false;
199198
}
200199

0 commit comments

Comments
 (0)