• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Deep-copy of dictionary keys (was: Is that really a bug at all?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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>)

  • Prev by Date: How do I know what class sent a message?
  • Next by Date: Re: How do I know what class sent a message?
  • Previous by thread: Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • Next by thread: Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • Index(es):
    • Date
    • Thread