3 ms·
You're updating the corners twice. Not really a problem with a simple assignment, but as no_protocol pointed out elsewhere [0], it could be if you ever wanted t
by dghf 10y ago
You're updating the corners twice. Not really a problem with a simple assignment, but as no_protocol pointed out elsewhere [0], it could be if you ever wanted to change that to, say, an increment.
Replace your second for statement with
for (i = 1; i < cols - 1; ++i) { ...
and you're golden.
[0] https://news.ycombinator.com/item?id=12794235 https://news.ycombinator.com/item?id=12794235
- stirner 10y agoYou're right, my version is unoptimized because I was trying to keep the code neat as in the article. I think that optimizing the code for hypothetical future reuse is a bit premature. You could make a performance argument, but this optimization is going to prevent just 2 memory accesses, which aren't going to matter much compared to all the rest. If I was chasing performance I would start by memset'ing the top and bottom edges since they're contiguous in memory.
- stirner 10y agoMy mistake - the optimization would prevent four memory accesses. Still O(1).