[Drawkit] Keeping objects sorted
Graham Cox
graham.cox at bigpond.com
Thu Jul 3 19:18:50 PDT 2008
On 4 Jul 2008, at 11:44 am, James Maxwell wrote:
> Hi Graham,
>
> Thanks for the tips. Thinking about it more, I figured it probably
> won't be a huge deal to simply offer the sorted versions to the
> methods that need them, when they need them.
Yep, that's an excellent idea. It avoids the need to synchronise two
lists and it's unlikely to be slow.
> I was a bit worried about it taking extra time to do this, but I
> don't imagine it will even be noticeable, really... I've been poking
> around with the new fast enumeration, which should help!
On a general note, you should usually avoid letting worries about
speed send you down a non-optimal programming path. Design it,
implement it, get it working, *then* measure its performance. If there
are any areas that need work the profiler will tell you what they are.
Assumptions about what is slow are rarely correct. In this case
sorting an array is going to be fast because internally it uses a very
good algorithm and various optimisations within Cocoa itself to ensure
it, and you're unlikely to ever be sorting more than a few thousand
objects. Typically drawing time (generating pixels) swamps any
calculation/sorting time so that's what's worth avoiding.
cheers, Graham
More information about the Drawkit
mailing list