use new instead of alloc init

Summary:
i saw this a lot in the codebase, it's not optimal bc we're using two selectors when we only need one.

  fastmod --extensions m,mm '\[\[(.*) alloc] init]' '[${1} new]' --dir xplat/js/react-native-github/*

i manually updated the callsites that this codemod couldn't handle (e.g., where there were more than one of these instances in a single line)

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D31776561

fbshipit-source-id: 1b16da240e8a79b54da67383d548921b82b05a9f
This commit is contained in:
Phillip Pan
2021-10-20 22:18:38 -07:00
committed by Facebook GitHub Bot
parent 9ac03361e6
commit def7dd857d
19 changed files with 33 additions and 34 deletions
+1 -1
View File
@@ -65,7 +65,7 @@
NSMutableArray<RCTGIFCoderFrame *> *frames = [NSMutableArray array];
for (size_t i = 0; i < frameCount; i++) {
RCTGIFCoderFrame *frame = [[RCTGIFCoderFrame alloc] init];
RCTGIFCoderFrame *frame = [RCTGIFCoderFrame new];
frame.index = i;
frame.duration = [self frameDurationAtIndex:i source:imageSource];
[frames addObject:frame];
+2 -2
View File
@@ -39,7 +39,7 @@ static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat sc
if (self = [super init]) {
_decodedImageCache = [NSCache new];
_decodedImageCache.totalCostLimit = 20 * 1024 * 1024; // 20 MB
_cacheStaleTimes = [[NSMutableDictionary alloc] init];
_cacheStaleTimes = [NSMutableDictionary new];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(clearCache)
@@ -151,7 +151,7 @@ static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat sc
static NSDateFormatter *formatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
formatter = [[NSDateFormatter alloc] init];
formatter = [NSDateFormatter new];
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
formatter.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
+1 -1
View File
@@ -87,7 +87,7 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
{
if ((self = [super initWithFrame:CGRectZero])) {
_bridge = bridge;
_imageView = [[RCTUIImageViewAnimated alloc] init];
_imageView = [RCTUIImageViewAnimated new];
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_imageView];
+1 -1
View File
@@ -130,7 +130,7 @@ static NSUInteger RCTDeviceFreeMemory() {
- (NSOperationQueue *)fetchQueue
{
if (!_fetchQueue) {
_fetchQueue = [[NSOperationQueue alloc] init];
_fetchQueue = [NSOperationQueue new];
_fetchQueue.maxConcurrentOperationCount = 1;
}
return _fetchQueue;
@@ -300,7 +300,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
self.backedTextInputView.inputView = nil;
} else {
// Hides keyboard, but keeps blinking cursor.
self.backedTextInputView.inputView = [[UIView alloc] init];
self.backedTextInputView.inputView = [UIView new];
}
}
@@ -607,7 +607,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
_hasInputAccesoryView = shouldHaveInputAccesoryView;
if (shouldHaveInputAccesoryView) {
UIToolbar *toolbarView = [[UIToolbar alloc] init];
UIToolbar *toolbarView = [UIToolbar new];
[toolbarView sizeToFit];
UIBarButtonItem *flexibleSpace =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
+1 -1
View File
@@ -811,7 +811,7 @@ static UIColor *RCTColorFromSemanticColorName(NSString *semanticColorName)
*/
static NSString *RCTSemanticColorNames()
{
NSMutableString *names = [[NSMutableString alloc] init];
NSMutableString *names = [NSMutableString new];
NSDictionary<NSString *, NSDictionary *> *colorMap = RCTSemanticColorsMap();
NSArray *allKeys =
[[[colorMap allKeys] mutableCopy] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
+1 -1
View File
@@ -350,7 +350,7 @@ RCT_EXPORT_MODULE()
[weakSelf setDefaultJSBundle];
return;
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSNumberFormatter *formatter = [NSNumberFormatter new];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSNumber *portNumber =
[formatter numberFromString:portTextField.text];
@@ -39,7 +39,7 @@ using namespace facebook::react;
static auto const defaultProps = std::make_shared<PullToRefreshViewProps const>();
_props = defaultProps;
_refreshControl = [[UIRefreshControl alloc] init];
_refreshControl = [UIRefreshControl new];
[_refreshControl addTarget:self
action:@selector(handleUIControlEventValueChanged)
forControlEvents:UIControlEventValueChanged];
@@ -105,7 +105,7 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg
static const auto defaultProps = std::make_shared<const ScrollViewProps>();
_props = defaultProps;
_childComponentViews = [[NSMutableArray alloc] init];
_childComponentViews = [NSMutableArray new];
_scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:self.bounds];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -67,7 +67,7 @@ using namespace facebook::react;
_props = defaultProps;
auto &props = *defaultProps;
_backedTextInputView = props.traits.multiline ? [[RCTUITextView alloc] init] : [[RCTUITextField alloc] init];
_backedTextInputView = props.traits.multiline ? [RCTUITextView new] : [RCTUITextField new];
_backedTextInputView.textInputDelegate = self;
_ignoreNextTextInputCall = NO;
_comingFromJS = NO;
@@ -465,7 +465,7 @@ using namespace facebook::react;
}
if (shouldHaveInputAccesoryView) {
UIToolbar *toolbarView = [[UIToolbar alloc] init];
UIToolbar *toolbarView = [UIToolbar new];
[toolbarView sizeToFit];
UIBarButtonItem *flexibleSpace =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
@@ -565,8 +565,7 @@ using namespace facebook::react;
- (void)_setMultiline:(BOOL)multiline
{
[_backedTextInputView removeFromSuperview];
UIView<RCTBackedTextInputViewProtocol> *backedTextInputView =
multiline ? [[RCTUITextView alloc] init] : [[RCTUITextField alloc] init];
UIView<RCTBackedTextInputViewProtocol> *backedTextInputView = multiline ? [RCTUITextView new] : [RCTUITextField new];
backedTextInputView.frame = _backedTextInputView.frame;
RCTCopyBackedTextInput(_backedTextInputView, backedTextInputView);
_backedTextInputView = backedTextInputView;
@@ -578,7 +578,7 @@ static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle)
layer.backgroundColor = _backgroundColor.CGColor;
} else {
if (!_borderLayer) {
_borderLayer = [[CALayer alloc] init];
_borderLayer = [CALayer new];
_borderLayer.zPosition = -1024.0f;
_borderLayer.frame = layer.bounds;
_borderLayer.magnificationFilter = kCAFilterNearest;
@@ -68,7 +68,7 @@ static Class<RCTComponentViewProtocol> RCTComponentViewClassWithName(const char
static RCTComponentViewFactory *componentViewFactory;
dispatch_once(&onceToken, ^{
componentViewFactory = [[RCTComponentViewFactory alloc] init];
componentViewFactory = [RCTComponentViewFactory new];
[componentViewFactory registerComponentViewClass:[RCTRootComponentView class]];
[componentViewFactory registerComponentViewClass:[RCTViewComponentView class]];
[componentViewFactory registerComponentViewClass:[RCTParagraphComponentView class]];
@@ -183,7 +183,7 @@ static Class<RCTComponentViewProtocol> RCTComponentViewClassWithName(const char
Class viewClass = componentViewClassDescriptor.viewClass;
return RCTComponentViewDescriptor{
.view = [[viewClass alloc] init],
.view = [viewClass new],
.observesMountingTransactionWillMount = componentViewClassDescriptor.observesMountingTransactionWillMount,
.observesMountingTransactionDidMount = componentViewClassDescriptor.observesMountingTransactionDidMount,
};
+1 -1
View File
@@ -155,7 +155,7 @@ static void RCTPerformMountInstructions(
- (instancetype)init
{
if (self = [super init]) {
_componentViewRegistry = [[RCTComponentViewRegistry alloc] init];
_componentViewRegistry = [RCTComponentViewRegistry new];
}
return self;
+2 -2
View File
@@ -91,8 +91,8 @@ static BackgroundExecutor RCTGetBackgroundExecutor()
_runtimeExecutor = runtimeExecutor;
_contextContainer = contextContainer;
_surfaceRegistry = [[RCTSurfaceRegistry alloc] init];
_mountingManager = [[RCTMountingManager alloc] init];
_surfaceRegistry = [RCTSurfaceRegistry new];
_mountingManager = [RCTMountingManager new];
_mountingManager.contextContainer = contextContainer;
_mountingManager.delegate = self;
@@ -322,17 +322,17 @@ static ParagraphShadowNode::ConcreteState::Shared stateWithShadowNode(
- (void)testAttributedString
{
ParagraphShadowNode::ConcreteState::Shared _stateA = stateWithShadowNode(ParagrahShadowNodeA_);
RCTParagraphComponentView *paragraphComponentViewA = [[RCTParagraphComponentView alloc] init];
RCTParagraphComponentView *paragraphComponentViewA = [RCTParagraphComponentView new];
[paragraphComponentViewA updateProps:ParagrahShadowNodeA_->getProps() oldProps:nullptr];
[paragraphComponentViewA updateState:_stateA oldState:nil];
ParagraphShadowNode::ConcreteState::Shared _stateB = stateWithShadowNode(ParagrahShadowNodeB_);
RCTParagraphComponentView *paragraphComponentViewB = [[RCTParagraphComponentView alloc] init];
RCTParagraphComponentView *paragraphComponentViewB = [RCTParagraphComponentView new];
[paragraphComponentViewB updateProps:ParagrahShadowNodeB_->getProps() oldProps:nullptr];
[paragraphComponentViewB updateState:_stateB oldState:nil];
ParagraphShadowNode::ConcreteState::Shared _stateC = stateWithShadowNode(ParagrahShadowNodeC_);
RCTParagraphComponentView *paragraphComponentViewC = [[RCTParagraphComponentView alloc] init];
RCTParagraphComponentView *paragraphComponentViewC = [RCTParagraphComponentView new];
[paragraphComponentViewC updateProps:ParagrahShadowNodeC_->getProps() oldProps:nullptr];
[paragraphComponentViewC updateState:_stateC oldState:nil];
@@ -358,7 +358,7 @@ static ParagraphShadowNode::ConcreteState::Shared stateWithShadowNode(
{
// initialize the paragraphComponentView to get the accessibilityElements
ParagraphShadowNode::ConcreteState::Shared _state = stateWithShadowNode(ParagrahShadowNodeA_);
RCTParagraphComponentView *paragraphComponentView = [[RCTParagraphComponentView alloc] init];
RCTParagraphComponentView *paragraphComponentView = [RCTParagraphComponentView new];
[paragraphComponentView updateProps:ParagrahShadowNodeA_->getProps() oldProps:nullptr];
[paragraphComponentView updateState:_state oldState:nil];
@@ -379,7 +379,7 @@ static ParagraphShadowNode::ConcreteState::Shared stateWithShadowNode(
- (void)testAccessibilityLinkWrappingMultipleLines
{
ParagraphShadowNode::ConcreteState::Shared _state = stateWithShadowNode(ParagrahShadowNodeB_);
RCTParagraphComponentView *paragraphComponentView = [[RCTParagraphComponentView alloc] init];
RCTParagraphComponentView *paragraphComponentView = [RCTParagraphComponentView new];
[paragraphComponentView updateProps:ParagrahShadowNodeB_->getProps() oldProps:nullptr];
[paragraphComponentView updateState:_state oldState:nil];
@@ -393,7 +393,7 @@ static ParagraphShadowNode::ConcreteState::Shared stateWithShadowNode(
- (void)testAccessibilityTruncatedText
{
ParagraphShadowNode::ConcreteState::Shared _state = stateWithShadowNode(ParagrahShadowNodeC_);
RCTParagraphComponentView *paragraphComponentView = [[RCTParagraphComponentView alloc] init];
RCTParagraphComponentView *paragraphComponentView = [RCTParagraphComponentView new];
[paragraphComponentView updateProps:ParagrahShadowNodeC_->getProps() oldProps:nullptr];
[paragraphComponentView updateState:_state oldState:nil];
@@ -458,7 +458,7 @@ static ParagraphShadowNode::ConcreteState::Shared stateWithShadowNode(
rootShadowNode->layoutIfNeeded();
ParagraphShadowNode::ConcreteState::Shared _state = stateWithShadowNode(paragrahShadowNode);
RCTParagraphComponentView *paragraphComponentView = [[RCTParagraphComponentView alloc] init];
RCTParagraphComponentView *paragraphComponentView = [RCTParagraphComponentView new];
[paragraphComponentView updateProps:paragrahShadowNode->getProps() oldProps:nullptr];
[paragraphComponentView updateState:_state oldState:nil];
+2 -2
View File
@@ -232,8 +232,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : unused)
return nil;
}
accessibilityActionsNameMap = [[NSMutableDictionary alloc] init];
accessibilityActionsLabelMap = [[NSMutableDictionary alloc] init];
accessibilityActionsNameMap = [NSMutableDictionary new];
accessibilityActionsLabelMap = [NSMutableDictionary new];
NSMutableArray *actions = [NSMutableArray array];
for (NSDictionary *action in self.accessibilityActions) {
if (action[@"name"]) {
+1 -1
View File
@@ -189,7 +189,7 @@ RCT_CUSTOM_VIEW_PROPERTY(accessibilityRole, UIAccessibilityTraits, RCTView)
RCT_CUSTOM_VIEW_PROPERTY(accessibilityState, NSDictionary, RCTView)
{
NSDictionary<NSString *, id> *state = json ? [RCTConvert NSDictionary:json] : nil;
NSMutableDictionary<NSString *, id> *newState = [[NSMutableDictionary<NSString *, id> alloc] init];
NSMutableDictionary<NSString *, id> *newState = [NSMutableDictionary<NSString *, id> new];
if (!state) {
return;
@@ -310,10 +310,10 @@ NSAttributedString *RCTNSAttributedStringFromAttributedString(const AttributedSt
static UIImage *placeholderImage;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
placeholderImage = [[UIImage alloc] init];
placeholderImage = [UIImage new];
});
NSMutableAttributedString *nsAttributedString = [[NSMutableAttributedString alloc] init];
NSMutableAttributedString *nsAttributedString = [NSMutableAttributedString new];
[nsAttributedString beginEditing];
@@ -17,7 +17,7 @@
- (void)testLabelCountInSyncWithRCTPLTag
{
RCTPerformanceLogger *logger = [[RCTPerformanceLogger alloc] init];
RCTPerformanceLogger *logger = [RCTPerformanceLogger new];
XCTAssertEqual([logger labelsForTags].count, RCTPLSize);
}