mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
[AsyncDisplayKit] Adopt #pragma once, remove last remaining dispatch_sync (UIScreen scale).
This commit is contained in:
@@ -6,8 +6,7 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#ifndef ASCollectionViewLayoutFacilitatorProtocol_h
|
||||
#define ASCollectionViewLayoutFacilitatorProtocol_h
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* This facilitator protocol is intended to help Layout to better
|
||||
@@ -41,5 +40,3 @@
|
||||
- (void)collectionViewWillPerformBatchUpdates;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* ASCollectionViewLayoutFacilitatorProtocol_h */
|
||||
|
||||
@@ -198,6 +198,12 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
class_replaceMethod(self, @selector(_staticInitialize), staticInitialize, "v:@");
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
// Ensure this value is cached on the main thread before needed in the background.
|
||||
ASScreenScale();
|
||||
}
|
||||
|
||||
+ (BOOL)layerBackedNodesEnabled
|
||||
{
|
||||
return YES;
|
||||
|
||||
@@ -250,7 +250,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
||||
|
||||
// Delegateify
|
||||
if (_delegateFlags.displayFinish) {
|
||||
if ([NSThread isMainThread])
|
||||
if (ASDisplayNodeThreadIsMain())
|
||||
[_delegate multiplexImageNodeDidFinishDisplay:self];
|
||||
else {
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
@@ -405,7 +405,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
||||
// Delegateify.
|
||||
// Note that we're using the params here instead of self.image and _displayedImageIdentifier because those can change before the async block below executes.
|
||||
if (_delegateFlags.updatedImageDisplayFinish) {
|
||||
if ([NSThread isMainThread])
|
||||
if (ASDisplayNodeThreadIsMain())
|
||||
[_delegate multiplexImageNode:self didDisplayUpdatedImage:image withIdentifier:displayedImageIdentifier];
|
||||
else {
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <AsyncDisplayKit/ASDimension.h>
|
||||
|
||||
#ifndef ASCollectionViewLayoutInspecting_h
|
||||
#define ASCollectionViewLayoutInspecting_h
|
||||
|
||||
@class ASCollectionView;
|
||||
@protocol ASCollectionDelegate;
|
||||
|
||||
@@ -56,6 +54,3 @@
|
||||
- (instancetype)initWithCollectionView:(ASCollectionView *)collectionView flowLayout:(UICollectionViewFlowLayout *)flowLayout;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* ASCollectionViewLayoutInspecting_h */
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#ifndef ASDataControllerSubclasses_Included
|
||||
#define ASDataControllerSubclasses_Included
|
||||
#pragma once
|
||||
|
||||
@class ASIndexedNodeContext;
|
||||
|
||||
@@ -162,5 +161,3 @@ typedef void (^ASDataControllerCompletionBlock)(NSArray<ASCellNode *> *nodes, NS
|
||||
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#ifndef ASDataController_Included
|
||||
#define ASDataController_Included
|
||||
#pragma once
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <AsyncDisplayKit/ASDealloc2MainObject.h>
|
||||
@@ -195,5 +194,3 @@ FOUNDATION_EXPORT NSString * const ASDataControllerRowNodeKind;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import "ASMainSerialQueue.h"
|
||||
|
||||
#import "ASThread.h"
|
||||
#import "ASInternalHelpers.h"
|
||||
|
||||
@interface ASMainSerialQueue ()
|
||||
{
|
||||
@@ -55,13 +56,7 @@
|
||||
} while (true);
|
||||
};
|
||||
|
||||
if ([NSThread isMainThread]) {
|
||||
mainThread();
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
mainThread();
|
||||
});
|
||||
}
|
||||
ASPerformBlockOnMainThread(mainThread);
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
|
||||
@@ -34,19 +34,6 @@ BOOL ASSubclassOverridesClassSelector(Class superclass, Class subclass, SEL sele
|
||||
return (superclassIMP != subclassIMP);
|
||||
}
|
||||
|
||||
static void ASDispatchOnceOnMainThread(dispatch_once_t *predicate, dispatch_block_t block)
|
||||
{
|
||||
if (ASDisplayNodeThreadIsMain()) {
|
||||
dispatch_once(predicate, block);
|
||||
} else {
|
||||
if (DISPATCH_EXPECT(*predicate == 0L, NO)) {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
dispatch_once(predicate, block);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASPerformBlockOnMainThread(void (^block)())
|
||||
{
|
||||
if (ASDisplayNodeThreadIsMain()) {
|
||||
@@ -67,12 +54,13 @@ void ASPerformBlockOnBackgroundThread(void (^block)())
|
||||
|
||||
CGFloat ASScreenScale()
|
||||
{
|
||||
static CGFloat _scale;
|
||||
static CGFloat __scale = 0.0;
|
||||
static dispatch_once_t onceToken;
|
||||
ASDispatchOnceOnMainThread(&onceToken, ^{
|
||||
_scale = [UIScreen mainScreen].scale;
|
||||
dispatch_once(&onceToken, ^{
|
||||
ASDisplayNodeCAssertMainThread();
|
||||
__scale = [[UIScreen mainScreen] scale];
|
||||
});
|
||||
return _scale;
|
||||
return __scale;
|
||||
}
|
||||
|
||||
CGFloat ASFloorPixelValue(CGFloat f)
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "ASEqualityHelpers.h"
|
||||
|
||||
#ifndef ComponentKit_ASTextKitAttributes_h
|
||||
#define ComponentKit_ASTextKitAttributes_h
|
||||
|
||||
@protocol ASTextKitTruncating;
|
||||
|
||||
extern NSString *const ASTextKitTruncationAttributeName;
|
||||
@@ -141,5 +140,3 @@ struct ASTextKitAttributes {
|
||||
|
||||
size_t hash() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -144,18 +144,6 @@
|
||||
|
||||
@implementation ASTableViewTests
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
/// Load a display node before the first test.
|
||||
/// Without this, running this suite specifically
|
||||
/// (as opposed to all tests) will cause a deadlock
|
||||
/// because of the dispatch_sync in `ASScreenScale()`.
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[ASDisplayNode new];
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Convert this to ARC.
|
||||
- (void)DISABLED_testTableViewDoesNotRetainItselfAndDelegate
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/NSException.h>
|
||||
#import <pthread.h>
|
||||
|
||||
#define ASDisplayNodeAssertWithSignalAndLogFunction(condition, description, logFunction, ...) NSAssert(condition, description, ##__VA_ARGS__);
|
||||
#define ASDisplayNodeCAssertWithSignalAndLogFunction(condition, description, logFunction, ...) NSCAssert(condition, description, ##__VA_ARGS__);
|
||||
@@ -30,11 +31,11 @@
|
||||
#define ASDisplayNodeAssertNotInstantiable() ASDisplayNodeAssertWithSignal(NO, nil, @"This class is not instantiable.");
|
||||
#define ASDisplayNodeAssertNotSupported() ASDisplayNodeAssertWithSignal(NO, nil, @"This method is not supported by class %@", [self class]);
|
||||
|
||||
#define ASDisplayNodeAssertMainThread() ASDisplayNodeAssertWithSignal([NSThread isMainThread], nil, @"This method must be called on the main thread")
|
||||
#define ASDisplayNodeCAssertMainThread() ASDisplayNodeCAssertWithSignal([NSThread isMainThread], nil, @"This function must be called on the main thread")
|
||||
#define ASDisplayNodeAssertMainThread() ASDisplayNodeAssertWithSignal(0 != pthread_main_np(), nil, @"This method must be called on the main thread")
|
||||
#define ASDisplayNodeCAssertMainThread() ASDisplayNodeCAssertWithSignal(0 != pthread_main_np(), nil, @"This function must be called on the main thread")
|
||||
|
||||
#define ASDisplayNodeAssertNotMainThread() ASDisplayNodeAssertWithSignal(![NSThread isMainThread], nil, @"This method must be called off the main thread")
|
||||
#define ASDisplayNodeCAssertNotMainThread() ASDisplayNodeCAssertWithSignal(![NSThread isMainThread], nil, @"This function must be called off the main thread")
|
||||
#define ASDisplayNodeAssertNotMainThread() ASDisplayNodeAssertWithSignal(0 == pthread_main_np(), nil, @"This method must be called off the main thread")
|
||||
#define ASDisplayNodeCAssertNotMainThread() ASDisplayNodeCAssertWithSignal(0 == pthread_main_np(), nil, @"This function must be called off the main thread")
|
||||
|
||||
#define ASDisplayNodeAssertFlag(X) ASDisplayNodeAssertWithSignal((1 == __builtin_popcount(X)), nil, nil)
|
||||
#define ASDisplayNodeCAssertFlag(X) ASDisplayNodeCAssertWithSignal((1 == __builtin_popcount(X)), nil, nil)
|
||||
|
||||
Reference in New Issue
Block a user