Skip to content

Commit

Permalink
Keep using unowned macro (TextureGroup#1626)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanton authored and matthewd1234 committed Aug 25, 2019
1 parent 88c5d03 commit b26e208
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Source/ASConfigurationInternal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ - (BOOL)activateExperimentalFeature:(ASExperimentalFeatures)requested

// Notify delegate if needed.
if (newlyTriggered != 0) {
__unsafe_unretained id<ASConfigurationDelegate> del = _config.delegate;
unowned id<ASConfigurationDelegate> del = _config.delegate;
dispatch_async(_delegateQueue, ^{
[del textureDidActivateExperimentalFeatures:newlyTriggered];
});
Expand Down
12 changes: 6 additions & 6 deletions Source/ASRunLoopQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ - (instancetype)initWithRunLoop:(CFRunLoopRef)runloop retainObjects:(BOOL)retain
}

// Self is guaranteed to outlive the observer. Without the high cost of a weak pointer,
// __unsafe_unretained allows us to avoid flagging the memory cycle detector.
__unsafe_unretained __typeof__(self) weakSelf = self;
// unowned(__unsafe_unretained) allows us to avoid flagging the memory cycle detector.
unowned __typeof__(self) weakSelf = self;
void (^handlerBlock) (CFRunLoopObserverRef observer, CFRunLoopActivity activity) = ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
[weakSelf processQueue];
};
Expand Down Expand Up @@ -230,7 +230,7 @@ - (void)processQueue
* object will be added to the autorelease pool. If the queue is strong,
* it will retain the object until we transfer it (retain it) in itemsToProcess.
*/
__unsafe_unretained id ptr = (__bridge id)[_internalQueue pointerAtIndex:i];
unowned id ptr = (__bridge id)[_internalQueue pointerAtIndex:i];
if (ptr != nil) {
foundItemCount++;
if (hasExecutionBlock) {
Expand Down Expand Up @@ -260,7 +260,7 @@ - (void)processQueue
as_activity_scope_verbose(as_activity_create("Process run loop queue batch", _rootActivity, OS_ACTIVITY_FLAG_DEFAULT));
const auto itemsEnd = itemsToProcess.cend();
for (auto iterator = itemsToProcess.begin(); iterator < itemsEnd; iterator++) {
__unsafe_unretained id value = *iterator;
unowned id value = *iterator;
_queueConsumer(value, isQueueDrained && iterator == itemsEnd - 1);
as_log_verbose(ASDisplayLog(), "processed %@", value);
}
Expand Down Expand Up @@ -375,8 +375,8 @@ - (instancetype)init
}

// Self is guaranteed to outlive the observer. Without the high cost of a weak pointer,
// __unsafe_unretained allows us to avoid flagging the memory cycle detector.
__unsafe_unretained __typeof__(self) weakSelf = self;
// unowned(__unsafe_unretained) allows us to avoid flagging the memory cycle detector.
unowned __typeof__(self) weakSelf = self;
_preTransactionObserver = CFRunLoopObserverCreateWithHandler(NULL, kCFRunLoopBeforeWaiting, true, kASASCATransactionQueueOrder, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
while (!weakSelf->_internalQueue.empty()) {
[weakSelf processQueue];
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASCollectionViewLayoutController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ - (void)allElementsForScrolling:(ASScrollDirection)scrollDirection rangeMode:(AS
}

// Avoid excessive retains and releases, as well as property calls. We know the element is kept alive by map.
__unsafe_unretained ASCollectionElement *e = [map elementForLayoutAttributes:la];
unowned ASCollectionElement *e = [map elementForLayoutAttributes:la];
if (e != nil && intersectsDisplay) {
[display addObject:e];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASElementMap.mm
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ - (id)mutableCopyWithZone:(NSZone *)zone

#pragma mark - NSFastEnumeration

- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id _Nullable __unsafe_unretained [])buffer count:(NSUInteger)len
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id _Nullable unowned [])buffer count:(NSUInteger)len
{
return [_elementToIndexPathMap countByEnumeratingWithState:state objects:buffer count:len];
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Details/ASPageTable.mm
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ + (ASPageToLayoutAttributesTable *)pageTableWithLayoutAttributes:(id<NSFastEnume

- (id)objectForPage:(ASPageCoordinate)page
{
__unsafe_unretained id key = (__bridge id)(void *)page;
unowned id key = (__bridge id)(void *)page;
return [self objectForKey:key];
}

- (void)setObject:(id)object forPage:(ASPageCoordinate)page
{
__unsafe_unretained id key = (__bridge id)(void *)page;
unowned id key = (__bridge id)(void *)page;
[self setObject:object forKey:key];
}

- (void)removeObjectForPage:(ASPageCoordinate)page
{
__unsafe_unretained id key = (__bridge id)(void *)page;
unowned id key = (__bridge id)(void *)page;
[self removeObjectForKey:key];
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Details/ASThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT BOOL ASDisplayNodeThreadIsMain()

/// Same as ASLockScope(1) but lock isn't retained (be careful).
#define ASLockScopeUnowned(nsLocking) \
__unsafe_unretained id<NSLocking> __lockToken __attribute__((cleanup(_ASLockScopeUnownedCleanup))) = nsLocking; \
unowned id<NSLocking> __lockToken __attribute__((cleanup(_ASLockScopeUnownedCleanup))) = nsLocking; \
[__lockToken lock];

ASDISPLAYNODE_INLINE void _ASLockScopeCleanup(id<NSLocking> __strong * const lockPtr) {
[*lockPtr unlock];
}

ASDISPLAYNODE_INLINE void _ASLockScopeUnownedCleanup(id<NSLocking> __unsafe_unretained * const lockPtr) {
ASDISPLAYNODE_INLINE void _ASLockScopeUnownedCleanup(id<NSLocking> unowned * const lockPtr) {
[*lockPtr unlock];
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASWeakSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (NSUInteger)count
return count;
}

- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(__unsafe_unretained id _Nonnull *)buffer count:(NSUInteger)len
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(unowned id _Nonnull *)buffer count:(NSUInteger)len
{
return [_hashTable countByEnumeratingWithState:state objects:buffer count:len];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Layout/ASLayoutElement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ - (instancetype)init

#if AS_TLS_AVAILABLE

static _Thread_local __unsafe_unretained ASLayoutElementContext *tls_context;
static _Thread_local unowned ASLayoutElementContext *tls_context;

void ASLayoutElementPushContext(ASLayoutElementContext *context)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Layout/ASLayoutSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (void)setChildren:(NSArray<id<ASLayoutElement>> *)children

#pragma mark - NSFastEnumeration

- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained _Nullable [_Nonnull])buffer count:(NSUInteger)len
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id unowned _Nullable [_Nonnull])buffer count:(NSUInteger)len
{
return [_childrenArray countByEnumeratingWithState:state objects:buffer count:len];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/ASDisplayNode+AsyncDisplay.mm
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ - (asyncdisplaykit_async_transaction_operation_block_t)_displayBlockWithAsynchro
Color the interval red if cancelled, green otherwise.
*/
#if AS_SIGNPOST_ENABLE
__unsafe_unretained id ptrSelf = (id)self;
unowned id ptrSelf = (id)self;
displayBlock = ^{
ASSignpostStart(LayerDisplay, ptrSelf, "%@", ASObjectDescriptionMakeTiny(ptrSelf));
id result = displayBlock();
Expand Down

0 comments on commit b26e208

Please sign in to comment.