Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
[pop] remove unecessary initial workaround
Browse files Browse the repository at this point in the history
Summary:

Original benchmarking improperly accounted for external factors. Manually performing the callback is only marginally faster.
  • Loading branch information
Kimon Tsinteris committed Apr 9, 2014
1 parent 4ade53c commit 124611f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
22 changes: 1 addition & 21 deletions FBKVOController/FBKVOController.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ static NSUInteger enumerate_flags(NSUInteger *ptrFlags)
return s;
}

static NSDictionary *change_dictionary_init(id object, NSUInteger options, NSString *keyPath)
{
NSDictionary *dict;
if (0 == (NSKeyValueObservingOptionNew & options)) {
dict = @{NSKeyValueChangeKindKey : @(NSKeyValueChangeSetting)};
} else {
id value = [object valueForKeyPath:keyPath];
dict = @{NSKeyValueChangeKindKey : @(NSKeyValueChangeSetting), NSKeyValueChangeNewKey : value ?: [NSNull null]};
}
return dict;
}

#pragma mark _FBKVOInfo -

/**
Expand Down Expand Up @@ -278,16 +266,8 @@ - (void)observe:(id)object info:(_FBKVOInfo *)info
[_infos addObject:info];
OSSpinLockUnlock(&_lock);

// remove costly initial
NSUInteger options = info->_options & ~NSKeyValueObservingOptionInitial;

// add observer
[object addObserver:self forKeyPath:info->_keyPath options:options context:(void *)info];

// manually perform initial callback if necessary
if (0 != (NSKeyValueObservingOptionInitial & info->_options)) {
[self observeValueForKeyPath:info->_keyPath ofObject:object change:change_dictionary_init(object, info->_options, info->_keyPath) context:(void *)info];
}
[object addObserver:self forKeyPath:info->_keyPath options:info->_options context:(void *)info];
}

- (void)unobserve:(id)object info:(_FBKVOInfo *)info
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Key-value observing is a particularly useful technique for communicating between
- Notification using blocks, custom actions, or NSKeyValueObserving callback.
- No exceptions on observer removal.
- Implicit observer removal on controller dealloc.
- Improved performance when using NSKeyValueObservingInitial.
- Thread-safety with special guards against observer resurrection – [rdar://15985376](http://openradar.appspot.com/radar?id=5305010728468480).

For more information on KVO, see Apple's [Introduction to Key-Value Observing](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html).
Expand Down

0 comments on commit 124611f

Please sign in to comment.