I need to create a set of objects (the types and values don't matter, as long as they are distinct) that have very fast comparisons. I'm currently using NSString for comparison, but I imagine there must be something faster. NSNumber maybe? Perhaps I could do an primitive comparison using its int value?
yes, of course. Should have thought of it myself. I'm still curious, though, even though this is the answer I'll use.
Ben Collins
2010-06-30 20:34:41
A:
The fastest object comparison method is NSObject's, which just compares pointer equality (self == argument).
If you want to create a bunch of objects that are only important for their identity, creating plain NSObjects is a decent way to go about it. You can manually compare them using pointer equality for maximum speed, and if some other class wants to use isEqual:, it's still as efficient as it can be.
Kind of an ineffective optimization in most cases, though.
Chuck
2010-06-30 21:46:38