Optimizing Flood Fill
RAM, despite being officially “random access,” isn’t truly random access these days. Modern computer memory is a complex hierarchical system which is optimized for common access patterns. Truly random access is quite slow compared to linearly reading or writing a long, contiguous chunk of memory.
When it comes to manipulating an image, this means that you always want to write code that iterates over
x
in the inner loop…