Re: sort descriptor optimization
Re: sort descriptor optimization
- Subject: Re: sort descriptor optimization
- From: "Adam R. Maxwell" <email@hidden>
- Date: Tue, 4 Jul 2006 15:43:41 -0700
On Jul 4, 2006, at 15:00, Matt Neuburg wrote:
On Tue, 4 Jul 2006 10:44:34 -0700, "Adam R. Maxwell"
<email@hidden>
said:
On Jul 2, 2006, at 16:53, Adam R. Maxwell wrote:
Hi all,
We have an application that uses a custom NSSortDescriptor subclass
to handle nil values and empty strings differently from default.
Essentially, it looks like this:
[...]
It looks like -[NSSortDescriptor compareObject:toObject:] does some
caching of key paths, or somehow bypasses valueForKeyPath:
altogether, but I can't figure out how to do this.
If anyone's interested in a test app to play with Shark, I've
posted it at <http://homepage.mac.com/amaxwell> as kvcTest.zip.
With our sort descriptor subclass, I'm seeing times in the ~50
second range on a 1.33 G4; with NSSortDescriptor, times are ~8
seconds.
Well, having received no advice on this matter, I ended up filing
rdar://problem/4612866 against valueForKeyPath: and rdar://problem/
4612871 against array sorting when using an NSSortDescriptor
subclass.
But you're doing this in such an odd way. Why are you subclassing
NSSortDescriptor at all? NSSortDescriptor itself tells you how it
wants you
to deal with this sort of situation; as it stands, it can be
initialized
with a comparison method selector. So, for example, if your
comparands are
NSStrings, you could implement a special comparator (via a category on
NSString) and use it in your NSSortDescriptor. Do you see the same
sort of
slowdown using that architecture?
We considered that. However, our users want nil values and empty
strings to sort last in an a-z ordered list, instead of first, for
all objects. Implementing this in NSSortDescriptor was also less
code, and doesn't require adding a special category on every object
that we sort.
As for some of your comparands being nil values, the obvious
suggestion is,
Don't Do That. m.
Thanks, but that is not an option. We need valueForKey: to return
nil when there is no value for that key.
-- Adam
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden