kolinkrewinkel/KKGridView — pull request #78 by jonsterling (2011-12-18 06:26:31+00:00)
Title: Optimize cell cleanup routine

So, `-_cleanupCells` gets run zillions of times during scrolling. I've replaced it with a version that runs almost twice as fast (the old one averaged about `1.2ms` on my iPhone, whereas the new one averages around `0.7ms`).

The main deal was that I replaced the nice high-level enumeration and filtering with an array of structs (effectively the tuple type `(KKGridViewCell*,KKIndexPath*)`. I'm sure everyone knows that you're not supposed to store Objective-C objects in C structs (unless you're using C++); this is because ARC won't know how to manage their memory. But for these objects, we *know* that they're already owned (by the `_visibleCells` dictionary); so, we can mark the pointers `__unsafe_unretained`, and ARC is happy. And we get a fast collection of cell/path pairs that we can deal with.

Let me know if you have any concerns or questions.