Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make experiment checks faster #1393

Merged
merged 3 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Source/ASConfigurationInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ NS_ASSUME_NONNULL_BEGIN
*
* The delegate will be notified asynchronously.
*/
AS_EXTERN BOOL ASActivateExperimentalFeature(ASExperimentalFeatures option);
#if DEBUG
#define ASActivateExperimentalFeature(opt) _ASActivateExperimentalFeature(opt)
#else
#define ASActivateExperimentalFeature(opt) ({\
static BOOL result;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{ result = _ASActivateExperimentalFeature(opt); });\
result;\
})
#endif

/**
* Internal function. Use the macro without the underbar.
*/
AS_EXTERN BOOL _ASActivateExperimentalFeature(ASExperimentalFeatures option);

/**
* Notify the configuration delegate that the framework initialized, if needed.
Expand Down
29 changes: 13 additions & 16 deletions Source/ASConfigurationInternal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
#import <AsyncDisplayKit/ASConfigurationDelegate.h>
#import <stdatomic.h>

#define ASGetSharedConfigMgr() (__bridge ASConfigurationManager *)ASConfigurationManager.sharedInstance
static ASConfigurationManager *ASSharedConfigurationManager;
static dispatch_once_t ASSharedConfigurationManagerOnceToken;

NS_INLINE ASConfigurationManager *ASConfigurationManagerGet() {
dispatch_once(&ASSharedConfigurationManagerOnceToken, ^{
ASSharedConfigurationManager = [[ASConfigurationManager alloc] init];
});
return ASSharedConfigurationManager;
}

@implementation ASConfigurationManager {
ASConfiguration *_config;
Expand All @@ -21,17 +29,6 @@ @implementation ASConfigurationManager {
_Atomic(ASExperimentalFeatures) _activatedExperiments;
}

/// Return CFTypeRef to avoid retain/release on this singleton.
+ (CFTypeRef)sharedInstance
{
static CFTypeRef inst;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
inst = (__bridge_retained CFTypeRef)[[ASConfigurationManager alloc] init];
});
return inst;
}

+ (ASConfiguration *)defaultConfiguration NS_RETURNS_RETAINED
{
ASConfiguration *config = [[ASConfiguration alloc] init];
Expand Down Expand Up @@ -96,19 +93,19 @@ - (BOOL)activateExperimentalFeature:(ASExperimentalFeatures)requested
// Define this even when !DEBUG, since we may run our tests in release mode.
+ (void)test_resetWithConfiguration:(ASConfiguration *)configuration
{
ASConfigurationManager *inst = ASGetSharedConfigMgr();
ASConfigurationManager *inst = ASConfigurationManagerGet();
inst->_config = configuration ?: [self defaultConfiguration];
atomic_store(&inst->_activatedExperiments, 0);
}

@end

BOOL ASActivateExperimentalFeature(ASExperimentalFeatures feature)
BOOL _ASActivateExperimentalFeature(ASExperimentalFeatures feature)
{
return [ASGetSharedConfigMgr() activateExperimentalFeature:feature];
return [ASConfigurationManagerGet() activateExperimentalFeature:feature];
}

void ASNotifyInitialized()
{
[ASGetSharedConfigMgr() frameworkDidInitialize];
[ASConfigurationManagerGet() frameworkDidInitialize];
}