Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
- Subject: Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
- From: Nicko van Someren <email@hidden>
- Date: Mon, 7 Jun 2004 18:06:55 +0100
On 7 Jun 2004, at 17:46, Marcel Weiher wrote:
On 7 Jun 2004, at 17:40, Nicko van Someren wrote:
On 7 Jun 2004, at 17:11, Marcel Weiher wrote:
Nicko: one of the reasons that the current implementation is broken
is that it *cannot* be fixed easily by subclassing!
That depends on what you call easy. It's trivial to do if you use a
wrapper class like this (typed in Mail.app):
That's a wrapper class. Not subclassing. Next.
That's a wrapper class for the references, to be used by the subclass
of NSDictionary. It retains the pointer to the original object across
to copying of the wrapper object.
Whereas the copying behavior *can* be added to a non-copying
implementation via subclassing.
It seems to me, looking at the documentation, that there are only two
extra messages that would have to be overridden to make the
non-copying version from what we have using the above wrapper class
(objectForKey: and keyEnumerator).
Yes. But in a subclass, -objectForKey: (and -setObjectForKey: ) are
precisely the methods you need from the superclass. And
-setObject:ForKey: does the copy. How are you going to un-copy that?
I don't un-copy it, I wrap the key objects in a wrapper that preserves
the object pointer across a copy. The sub-class for -setObject:ForKey:
calls the super method with a wrapper of the key; the parent dictionary
code copies the wrapper but leaves the wrapped reference the same
(since it is a shallow copy). The -objectForKey: uses the parent
dictionary's objectForKey: to look up the provided key in the wrappers
and the -keyEnumerator is tweaked to take the key enumerator from the
parent and unwrap the keys as the come out.
That was one of the original points I made.
It would really help if people would (a) read and (b) understand
what was written before responding.
I did read and understand your previous postings,
No you didn't, because we've already had the wrapper a couple of times
before.
Without wishing to descend into name-calling, it seems it is you who
did not understand my post.
I just happen to disagree with them.
You need to read + understand. Then you can disagree.
I did. I submit that you should too.
Nicko
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.