mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
iOS: Migrate FlutterEngineGroup to ARC (flutter/engine#55503)
This migrates FlutterEngineGroup to automatic reference counting. It also migrates `enginesCreatedCount` from an ivar to property syntax. I'll look at migrating engine from `NSMutableArray<NSValue*>` to a weak pointer array in a followup patch since it's orthogonal to ARC migration. Issue: https://github.com/flutter/flutter/issues/137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
parent
b99e758ee1
commit
219d952197
@ -70,6 +70,7 @@ source_set("flutter_framework_source_arc") {
|
||||
"framework/Source/FlutterDartVMServicePublisher.mm",
|
||||
"framework/Source/FlutterEmbedderKeyResponder.h",
|
||||
"framework/Source/FlutterEmbedderKeyResponder.mm",
|
||||
"framework/Source/FlutterEngineGroup.mm",
|
||||
"framework/Source/FlutterHeadlessDartRunner.mm",
|
||||
"framework/Source/FlutterKeyPrimaryResponder.h",
|
||||
"framework/Source/FlutterKeySecondaryResponder.h",
|
||||
@ -182,7 +183,6 @@ source_set("flutter_framework_source") {
|
||||
# New files are highly encouraged to be in ARC.
|
||||
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
|
||||
"framework/Source/FlutterEngine.mm",
|
||||
"framework/Source/FlutterEngineGroup.mm",
|
||||
"framework/Source/FlutterEngine_Internal.h",
|
||||
"framework/Source/FlutterPlatformPlugin.h",
|
||||
"framework/Source/FlutterPlatformPlugin.mm",
|
||||
|
||||
@ -38,7 +38,7 @@ FLUTTER_DARWIN_EXPORT
|
||||
/**
|
||||
* Arguments passed as a list of string to Dart's entrypoint function.
|
||||
*/
|
||||
@property(nonatomic, retain, nullable) NSArray<NSString*>* entrypointArgs;
|
||||
@property(nonatomic, copy, nullable) NSArray<NSString*>* entrypointArgs;
|
||||
@end
|
||||
|
||||
/**
|
||||
|
||||
@ -5,45 +5,30 @@
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
|
||||
|
||||
FLUTTER_ASSERT_ARC
|
||||
|
||||
@implementation FlutterEngineGroupOptions
|
||||
|
||||
- (void)dealloc {
|
||||
[_entrypoint release];
|
||||
[_libraryURI release];
|
||||
[_initialRoute release];
|
||||
[_entrypointArgs release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface FlutterEngineGroup ()
|
||||
@property(nonatomic, copy) NSString* name;
|
||||
@property(nonatomic, retain) NSMutableArray<NSValue*>* engines;
|
||||
@property(nonatomic, retain) FlutterDartProject* project;
|
||||
@property(nonatomic, strong) NSMutableArray<NSValue*>* engines;
|
||||
@property(nonatomic, copy) FlutterDartProject* project;
|
||||
@property(nonatomic, assign) NSUInteger enginesCreatedCount;
|
||||
@end
|
||||
|
||||
@implementation FlutterEngineGroup {
|
||||
int _enginesCreatedCount;
|
||||
}
|
||||
@implementation FlutterEngineGroup
|
||||
|
||||
- (instancetype)initWithName:(NSString*)name project:(nullable FlutterDartProject*)project {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_name = [name copy];
|
||||
_engines = [[NSMutableArray<NSValue*> alloc] init];
|
||||
_project = [project retain];
|
||||
_project = project;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_name release];
|
||||
[_engines release];
|
||||
[_project release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
|
||||
libraryURI:(nullable NSString*)libraryURI {
|
||||
return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
|
||||
@ -52,7 +37,7 @@
|
||||
- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
|
||||
libraryURI:(nullable NSString*)libraryURI
|
||||
initialRoute:(nullable NSString*)initialRoute {
|
||||
FlutterEngineGroupOptions* options = [[[FlutterEngineGroupOptions alloc] init] autorelease];
|
||||
FlutterEngineGroupOptions* options = [[FlutterEngineGroupOptions alloc] init];
|
||||
options.entrypoint = entrypoint;
|
||||
options.libraryURI = libraryURI;
|
||||
options.initialRoute = initialRoute;
|
||||
@ -79,7 +64,8 @@
|
||||
initialRoute:initialRoute
|
||||
entrypointArgs:entrypointArgs];
|
||||
}
|
||||
[_engines addObject:[NSValue valueWithPointer:engine]];
|
||||
// TODO(cbracken): https://github.com/flutter/flutter/issues/155943
|
||||
[self.engines addObject:[NSValue valueWithPointer:(__bridge void*)engine]];
|
||||
|
||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||
[center addObserver:self
|
||||
@ -91,13 +77,14 @@
|
||||
}
|
||||
|
||||
- (FlutterEngine*)makeEngine {
|
||||
NSString* engineName = [NSString stringWithFormat:@"%@.%d", self.name, ++_enginesCreatedCount];
|
||||
FlutterEngine* result = [[FlutterEngine alloc] initWithName:engineName project:self.project];
|
||||
return [result autorelease];
|
||||
NSString* engineName =
|
||||
[NSString stringWithFormat:@"%@.%lu", self.name, ++self.enginesCreatedCount];
|
||||
return [[FlutterEngine alloc] initWithName:engineName project:self.project];
|
||||
}
|
||||
|
||||
- (void)onEngineWillBeDealloced:(NSNotification*)notification {
|
||||
[_engines removeObject:[NSValue valueWithPointer:notification.object]];
|
||||
// TODO(cbracken): https://github.com/flutter/flutter/issues/155943
|
||||
[self.engines removeObject:[NSValue valueWithPointer:(__bridge void*)notification.object]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user