From b6feecae70758bbe2784c75fdf747d27c83aa3c4 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Tue, 19 Feb 2013 12:06:48 -0500 Subject: [PATCH] minor optimization so that newObject and includedKeys use the same code --- AppKit/CPDictionaryController.j | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/AppKit/CPDictionaryController.j b/AppKit/CPDictionaryController.j index 7475424b7..b22125735 100644 --- a/AppKit/CPDictionaryController.j +++ b/AppKit/CPDictionaryController.j @@ -57,13 +57,20 @@ while ([keys containsObject:newKey]) newKey = [CPString stringWithFormat:@"%@%i", _initialKey, ++count]; - [_contentDictionary setObject:_initialValue forKey:newKey]; + return [self _newObjectWithKey:newKey value:_initialValue]; +} - var keyValuePairProtocol = [_CPDictionaryControllerKeyValuePair new]; - keyValuePairProtocol._key = newKey; - keyValuePairProtocol._dictionary = _contentDictionary; - keyValuePairProtocol._controller = self; - return keyValuePairProtocol; +- (id)_newObjectWithKey:(CPString)aKey value:(id)aValue +{ + var aNewObject = [_CPDictionaryControllerKeyValuePair new]; + + aNewObject._dictionary = _contentDictionary; + aNewObject._controller = self; + aNewObject._key = aKey; + if (aValue !== nil) + [aNewObject setValue:aValue]; + + return aNewObject } - (CPDictionary)contentDictionary @@ -90,21 +97,13 @@ obj; while ((obj = [iter nextObject]) !== nil) - { if (![_excludedKeys containsObject:obj]) - { - var keyValuePairProtocol = [_CPDictionaryControllerKeyValuePair new]; - keyValuePairProtocol._key = obj; - keyValuePairProtocol._dictionary = _contentDictionary; - keyValuePairProtocol._controller = self; - [array addObject:keyValuePairProtocol]; - } - } + [array addObject:[self _newObjectWithKey:obj value:nil]]; + [super setContent:array]; } - @end @@ -138,6 +137,9 @@ var CPIncludedKeys = @"CPIncludedKeys", @end + + + @implementation _CPDictionaryControllerKeyValuePair : CPObject { CPString _key @accessors(property=key);