Deep-copy of dictionary keys (was: Is that really a bug at all?)
Deep-copy of dictionary keys (was: Is that really a bug at all?)
- Subject: Deep-copy of dictionary keys (was: Is that really a bug at all?)
- From: Allan Odgaard <email@hidden>
- Date: Mon, 7 Jun 2004 05:36:58 +0200
On 7. Jun 2004, at 3:37, Marcel Weiher wrote:
[...] you can't easily/efficiently build a NSGenericDictionary on top
of a NSKeyCopyingDictionary [...]
Yes you can, something like this should work:
@implementation NSGenericDictionary
- (void)setObject:(id)anObject forKey:(id)aKey
{
[super setObject:anObject forKey:[Reference
referenceWithObject:aKey]];
}
@end
@implementation Reference
- (id)initWithObject:(id)anObject
{
if(self = [super init])
object = [anObject retain];
return self;
}
+ (Reference)referenceWithObject:(id)anObject
{
return [[[Reference alloc] initWithObject:anObject] autorelease];
}
- (id)copyWithZone:(NSZone*)zone
{
return [[[Reference allocWithZone:zone] initWithObject:object]
autorelease];
}
- (void)dealloc
{
[object release];
[super dealloc];
}
- (void)forwardInvocation:(NSInvocation*)anInvocation
{
[anInvocation invokeWithTarget:object];
}
- (NSMethodSignature*)methodSignatureForSelector:(SEL)aSelector
{
return [object methodSignatureForSelector:aSelector];
}
@end
So having the NSKeyCopyingDictionary be the generic NSDictionary
behavior is, in a word, wrong.
That is really a religious statement!
One problem with deep-copying keys is, that it has a memory and
run-time performance overhead. Especially with Cocoa, there is a lot
of keys which are shared among many different NSDictionary instances.
Also, making a copy of a dictionary, should that then be deep-copy for
the key and shallow-copy for the value?
_______________________________________________
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.
References: | |
| >Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>) |
| >Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Ondra Cada <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Brent Gulanowski <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Ondra Cada <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Brent Gulanowski <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: "Louis C. Sacha" <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Nat! <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Nat! <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>) |