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

Remove let and var macros now that we're all-C++ #1312

Merged
merged 4 commits into from
Jan 17, 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
8 changes: 4 additions & 4 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ - (void)didLoad
[view setContentOffset:contentOffset animated:pendingState.animatesContentOffset];
}

let tuningParametersVector = pendingState->_tuningParameters;
let tuningParametersVectorSize = tuningParametersVector.size();
const auto tuningParametersVector = pendingState->_tuningParameters;
const auto tuningParametersVectorSize = tuningParametersVector.size();
for (NSInteger rangeMode = 0; rangeMode < tuningParametersVectorSize; rangeMode++) {
let tuningparametersRangeModeVector = tuningParametersVector[rangeMode];
let tuningParametersVectorRangeModeSize = tuningparametersRangeModeVector.size();
const auto tuningparametersRangeModeVector = tuningParametersVector[rangeMode];
const auto tuningParametersVectorRangeModeSize = tuningparametersRangeModeVector.size();
for (NSInteger rangeType = 0; rangeType < tuningParametersVectorRangeModeSize; rangeType++) {
ASRangeTuningParameters tuningParameters = tuningparametersRangeModeVector[rangeType];
[_rangeController setTuningParameters:tuningParameters
Expand Down
10 changes: 5 additions & 5 deletions Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath

// If the data source implements canMoveItem, let them decide.
Copy link
Member

@nguyenhuy nguyenhuy Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“constant auto them decide” makes a good joke though lol

if (_asyncDataSourceFlags.collectionNodeCanMoveItem) {
if (let cellNode = [self nodeForItemAtIndexPath:indexPath]) {
if (ASCellNode *cellNode = [self nodeForItemAtIndexPath:indexPath]) {
GET_COLLECTIONNODE_OR_RETURN(collectionNode, NO);
return [_asyncDataSource collectionNode:collectionNode canMoveItemWithNode:cellNode];
}
Expand All @@ -1578,7 +1578,7 @@ - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(N

// Inform the data source first, in case they call nodeForItemAtIndexPath:.
// We want to make sure we return them the node for the item they have in mind.
if (let collectionNode = self.collectionNode) {
if (ASCollectionNode *collectionNode = self.collectionNode) {
[_asyncDataSource collectionNode:collectionNode moveItemAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];
}

Expand Down Expand Up @@ -2083,7 +2083,7 @@ - (ASCellNodeBlock)dataController:(ASDataController *)dataController supplementa
- (NSArray<NSString *> *)dataController:(ASDataController *)dataController supplementaryNodeKindsInSections:(NSIndexSet *)sections
{
if (_asyncDataSourceFlags.collectionNodeSupplementaryElementKindsInSection) {
let kinds = [[NSMutableSet<NSString *> alloc] init];
const auto kinds = [[NSMutableSet<NSString *> alloc] init];
GET_COLLECTIONNODE_OR_RETURN(collectionNode, @[]);
[sections enumerateIndexesUsingBlock:^(NSUInteger section, BOOL * _Nonnull stop) {
NSArray<NSString *> *kindsForSection = [_asyncDataSource collectionNode:collectionNode supplementaryElementKindsInSection:section];
Expand Down Expand Up @@ -2218,7 +2218,7 @@ - (void)rangeController:(ASRangeController *)rangeController updateWithChangeSet
[_layoutFacilitator collectionViewWillPerformBatchUpdates];

__block NSUInteger numberOfUpdates = 0;
let completion = ^(BOOL finished) {
const auto completion = ^(BOOL finished) {
as_activity_scope(as_activity_create("Handle collection update completion", changeSet.rootActivity, OS_ACTIVITY_FLAG_DEFAULT));
as_log_verbose(ASCollectionLog(), "Update animation finished %{public}@", self.collectionNode);
// Flush any range changes that happened as part of the update animations ending.
Expand Down Expand Up @@ -2319,7 +2319,7 @@ - (void)nodesDidRelayout:(NSArray<ASCellNode *> *)nodes
return;
}

let uikitIndexPaths = ASArrayByFlatMapping(nodes, ASCellNode *node, [self indexPathForNode:node]);
const auto uikitIndexPaths = ASArrayByFlatMapping(nodes, ASCellNode *node, [self indexPathForNode:node]);

[_layoutFacilitator collectionViewWillEditCellsAtIndexPaths:uikitIndexPaths batched:NO];

Expand Down
4 changes: 2 additions & 2 deletions Source/ASConfiguration.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
{
if (self = [super init]) {
if (dictionary != nil) {
let featureStrings = ASDynamicCast(dictionary[@"experimental_features"], NSArray);
let version = ASDynamicCast(dictionary[@"version"], NSNumber).integerValue;
const auto featureStrings = ASDynamicCast(dictionary[@"experimental_features"], NSArray);
const auto version = ASDynamicCast(dictionary[@"version"], NSNumber).integerValue;
if (version != ASConfigurationSchemaCurrentVersion) {
NSLog(@"Texture warning: configuration schema is old version (%ld vs %ld)", (long)version, (long)ASConfigurationSchemaCurrentVersion);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ASConfigurationInternal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)frameworkDidInitialize
}
_frameworkInitialized = YES;

let delegate = _config.delegate;
const auto delegate = _config.delegate;
if ([delegate respondsToSelector:@selector(textureDidInitialize)]) {
[delegate textureDidInitialize];
}
Expand Down
14 changes: 7 additions & 7 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ - (void)transitionLayoutWithSizeRange:(ASSizeRange)constrainedSize
ASDN::MutexLocker l(__instanceLock__);

// Update calculated layout
let previousLayout = _calculatedDisplayNodeLayout;
let pendingLayout = ASDisplayNodeLayout(newLayout,
const auto previousLayout = _calculatedDisplayNodeLayout;
const auto pendingLayout = ASDisplayNodeLayout(newLayout,
constrainedSize,
constrainedSize.max,
newLayoutVersion);
Expand Down Expand Up @@ -775,10 +775,10 @@ - (void)animateLayoutTransition:(id<ASContextTransitioning>)context

NSArray<ASDisplayNode *> *removedSubnodes = [context removedSubnodes];
NSMutableArray<ASDisplayNode *> *insertedSubnodes = [[context insertedSubnodes] mutableCopy];
let movedSubnodes = [[NSMutableArray<ASDisplayNode *> alloc] init];
const auto movedSubnodes = [[NSMutableArray<ASDisplayNode *> alloc] init];

let insertedSubnodeContexts = [[NSMutableArray<_ASAnimatedTransitionContext *> alloc] init];
let removedSubnodeContexts = [[NSMutableArray<_ASAnimatedTransitionContext *> alloc] init];
const auto insertedSubnodeContexts = [[NSMutableArray<_ASAnimatedTransitionContext *> alloc] init];
const auto removedSubnodeContexts = [[NSMutableArray<_ASAnimatedTransitionContext *> alloc] init];

for (ASDisplayNode *subnode in [context subnodesForKey:ASTransitionContextToLayoutKey]) {
if ([insertedSubnodes containsObject:subnode] == NO) {
Expand Down Expand Up @@ -916,9 +916,9 @@ - (void)_assertSubnodeState
NSArray *subnodes = [self subnodes];
NSArray *sublayouts = _calculatedDisplayNodeLayout.layout.sublayouts;

let currentSubnodes = [[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality
const auto currentSubnodes = [[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality
capacity:subnodes.count];
let layoutSubnodes = [[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality
const auto layoutSubnodes = [[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality
capacity:sublayouts.count];;
for (ASDisplayNode *subnode in subnodes) {
[currentSubnodes addObject:subnode];
Expand Down
2 changes: 1 addition & 1 deletion Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ - (void)setupYogaCalculatedLayout
for (ASDisplayNode *subnode in self.yogaChildren) {
rawSublayouts[i++] = [subnode layoutForYogaNode];
}
let sublayouts = [NSArray<ASLayout *> arrayByTransferring:rawSublayouts count:childCount];
const auto sublayouts = [NSArray<ASLayout *> arrayByTransferring:rawSublayouts count:childCount];

// The layout for self should have position CGPointNull, but include the calculated size.
CGSize size = CGSizeMake(YGNodeLayoutGetWidth(yogaNode), YGNodeLayoutGetHeight(yogaNode));
Expand Down
6 changes: 3 additions & 3 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ - (void)_didLoad
[self didLoad];

__instanceLock__.lock();
let onDidLoadBlocks = ASTransferStrong(_onDidLoadBlocks);
const auto onDidLoadBlocks = ASTransferStrong(_onDidLoadBlocks);
__instanceLock__.unlock();

for (ASDisplayNodeDidLoadBlock block in onDidLoadBlocks) {
Expand Down Expand Up @@ -3784,7 +3784,7 @@ - (NSString *)description
- (NSString *)debugDescription
{
ASPushMainThreadAssertionsDisabled();
let result = ASObjectDescriptionMake(self, [self propertiesForDebugDescription]);
const auto result = ASObjectDescriptionMake(self, [self propertiesForDebugDescription]);
ASPopMainThreadAssertionsDisabled();
return result;
}
Expand Down Expand Up @@ -3869,7 +3869,7 @@ - (NSString *)detailedLayoutDescription
{
ASPushMainThreadAssertionsDisabled();
ASDN::MutexLocker l(__instanceLock__);
let props = [[NSMutableArray<NSDictionary *> alloc] init];
const auto props = [[NSMutableArray<NSDictionary *> alloc] init];

[props addObject:@{ @"layoutVersion": @(_layoutVersion.load()) }];
[props addObject:@{ @"bounds": [NSValue valueWithCGRect:self.bounds] }];
Expand Down
2 changes: 1 addition & 1 deletion Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ - (UIImage *)placeholderImage

- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
let image = ASLockedSelf(_image);
const auto image = ASLockedSelf(_image);

if (image == nil) {
return [super calculateSizeThatFits:constrainedSize];
Expand Down
2 changes: 1 addition & 1 deletion Source/ASMainThreadDeallocation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ @implementation NSObject (ASNeedsMainThreadDeallocation)

+ (BOOL)needsMainThreadDeallocation
{
let name = class_getName(self);
const auto name = class_getName(self);
if (0 == strncmp(name, "AV", 2) || 0 == strncmp(name, "UI", 2) || 0 == strncmp(name, "CA", 2)) {
return YES;
}
Expand Down
12 changes: 6 additions & 6 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
// Call out to the delegate.
if (_delegateFlags.delegateDidLoadImageWithInfo) {
ASUnlockScope(self);
let info = [[ASNetworkImageLoadInfo alloc] initWithURL:url sourceType:ASNetworkImageSourceSynchronousCache downloadIdentifier:nil userInfo:nil];
const auto info = [[ASNetworkImageLoadInfo alloc] initWithURL:url sourceType:ASNetworkImageSourceSynchronousCache downloadIdentifier:nil userInfo:nil];
[delegate imageNode:self didLoadImage:result info:info];
} else if (_delegateFlags.delegateDidLoadImage) {
ASUnlockScope(self);
Expand Down Expand Up @@ -662,7 +662,7 @@ - (void)_lazilyLoadImageIfNecessary
} else {
// First try to load the path directly, for efficiency assuming a developer who
// doesn't want caching is trying to be as minimal as possible.
var nonAnimatedImage = [[UIImage alloc] initWithContentsOfFile:URL.path];
auto nonAnimatedImage = [[UIImage alloc] initWithContentsOfFile:URL.path];
if (nonAnimatedImage == nil) {
// If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the
// extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage.
Expand All @@ -675,7 +675,7 @@ - (void)_lazilyLoadImageIfNecessary
// If the file may be an animated gif and then created an animated image.
id<ASAnimatedImageProtocol> animatedImage = nil;
if (self->_downloaderFlags.downloaderImplementsAnimatedImage) {
let data = [[NSData alloc] initWithContentsOfURL:URL];
const auto data = [[NSData alloc] initWithContentsOfURL:URL];
if (data != nil) {
animatedImage = [self->_downloader animatedImageWithData:data];

Expand All @@ -698,7 +698,7 @@ - (void)_lazilyLoadImageIfNecessary

if (self->_delegateFlags.delegateDidLoadImageWithInfo) {
ASUnlockScope(self);
let info = [[ASNetworkImageLoadInfo alloc] initWithURL:URL sourceType:ASNetworkImageSourceFileURL downloadIdentifier:nil userInfo:nil];
const auto info = [[ASNetworkImageLoadInfo alloc] initWithURL:URL sourceType:ASNetworkImageSourceFileURL downloadIdentifier:nil userInfo:nil];
[delegate imageNode:self didLoadImage:self.image info:info];
} else if (self->_delegateFlags.delegateDidLoadImage) {
ASUnlockScope(self);
Expand All @@ -707,7 +707,7 @@ - (void)_lazilyLoadImageIfNecessary
});
} else {
__weak __typeof__(self) weakSelf = self;
let finished = ^(id <ASImageContainerProtocol>imageContainer, NSError *error, id downloadIdentifier, ASNetworkImageSourceType imageSource, id userInfo) {
const auto finished = ^(id <ASImageContainerProtocol>imageContainer, NSError *error, id downloadIdentifier, ASNetworkImageSourceType imageSource, id userInfo) {
ASPerformBlockOnBackgroundThread(^{
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
Expand Down Expand Up @@ -753,7 +753,7 @@ - (void)_lazilyLoadImageIfNecessary
if (newImage) {
if (strongSelf->_delegateFlags.delegateDidLoadImageWithInfo) {
calloutBlock = ^(ASNetworkImageNode *strongSelf) {
let info = [[ASNetworkImageLoadInfo alloc] initWithURL:URL sourceType:imageSource downloadIdentifier:downloadIdentifier userInfo:userInfo];
const auto info = [[ASNetworkImageLoadInfo alloc] initWithURL:URL sourceType:imageSource downloadIdentifier:downloadIdentifier userInfo:userInfo];
[delegate imageNode:strongSelf didLoadImage:newImage info:info];
};
} else if (strongSelf->_delegateFlags.delegateDidLoadImage) {
Expand Down
20 changes: 10 additions & 10 deletions Source/ASRunLoopQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ - (void)releaseObjectInBackground:(id _Nullable __strong *)objectPtr
NSParameterAssert(objectPtr != NULL);

// Cast to CFType so we can manipulate retain count manually.
let cfPtr = (CFTypeRef *)(void *)objectPtr;
const auto cfPtr = (CFTypeRef *)(void *)objectPtr;
if (!cfPtr || !*cfPtr) {
return;
}

_lock.lock();
let isFirstEntry = _queue.empty();
const auto isFirstEntry = _queue.empty();
// Push the pointer into our queue and clear their pointer.
// This "steals" the +1 from ARC and nils their pointer so they can't
// access or release the object.
Expand All @@ -80,9 +80,9 @@ - (void)releaseObjectInBackground:(id _Nullable __strong *)objectPtr
- (void)drain
{
_lock.lock();
let q = std::move(_queue);
const auto q = std::move(_queue);
_lock.unlock();
for (let ref : q) {
for (CFTypeRef ref : q) {
// NOTE: Could check that retain count is 1 and retry later if not.
CFRelease(ref);
}
Expand Down Expand Up @@ -256,11 +256,11 @@ - (void)processQueue
}

// itemsToProcess will be empty if _queueConsumer == nil so no need to check again.
let count = itemsToProcess.size();
const auto count = itemsToProcess.size();
if (count > 0) {
as_activity_scope_verbose(as_activity_create("Process run loop queue batch", _rootActivity, OS_ACTIVITY_FLAG_DEFAULT));
let itemsEnd = itemsToProcess.cend();
for (var iterator = itemsToProcess.begin(); iterator < itemsEnd; iterator++) {
const auto itemsEnd = itemsToProcess.cend();
for (auto iterator = itemsToProcess.begin(); iterator < itemsEnd; iterator++) {
__unsafe_unretained id value = *iterator;
_queueConsumer(value, isQueueDrained && iterator == itemsEnd - 1);
as_log_verbose(ASDisplayLog(), "processed %@", value);
Expand Down Expand Up @@ -460,11 +460,11 @@ - (void)processQueue
}

// itemsToProcess will be empty if _queueConsumer == nil so no need to check again.
let count = itemsToProcess.size();
const auto count = itemsToProcess.size();
if (count > 0) {
as_activity_scope_verbose(as_activity_create("Process run loop queue batch", _rootActivity, OS_ACTIVITY_FLAG_DEFAULT));
let itemsEnd = itemsToProcess.cend();
for (var iterator = itemsToProcess.begin(); iterator < itemsEnd; iterator++) {
const auto itemsEnd = itemsToProcess.cend();
for (auto iterator = itemsToProcess.begin(); iterator < itemsEnd; iterator++) {
__unsafe_unretained id value = *iterator;
[value prepareForCATransactionCommit];
as_log_verbose(ASDisplayLog(), "processed %@", value);
Expand Down
8 changes: 4 additions & 4 deletions Source/ASTableNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ - (void)didLoad
[view setContentOffset:contentOffset animated:pendingState.animatesContentOffset];
}

let tuningParametersVector = pendingState->_tuningParameters;
let tuningParametersVectorSize = tuningParametersVector.size();
const auto tuningParametersVector = pendingState->_tuningParameters;
const auto tuningParametersVectorSize = tuningParametersVector.size();
for (NSInteger rangeMode = 0; rangeMode < tuningParametersVectorSize; rangeMode++) {
let tuningparametersRangeModeVector = tuningParametersVector[rangeMode];
let tuningParametersVectorRangeModeSize = tuningparametersRangeModeVector.size();
const auto tuningparametersRangeModeVector = tuningParametersVector[rangeMode];
const auto tuningParametersVectorRangeModeSize = tuningparametersRangeModeVector.size();
for (NSInteger rangeType = 0; rangeType < tuningParametersVectorRangeModeSize; rangeType++) {
ASRangeTuningParameters tuningParameters = tuningparametersRangeModeVector[rangeType];
[_rangeController setTuningParameters:tuningParameters
Expand Down
4 changes: 2 additions & 2 deletions Source/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ - (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode waitingIfNeede

- (NSArray<ASCellNode *> *)visibleNodes
{
let elements = [self visibleElementsForRangeController:_rangeController];
const auto elements = [self visibleElementsForRangeController:_rangeController];
return ASArrayByFlatMapping(elements, ASCollectionElement *e, e.node);
}

Expand Down Expand Up @@ -765,7 +765,7 @@ - (void)layoutSubviews
NSArray<ASCellNode *> *nodes = [_cellsForLayoutUpdates allObjects];
[_cellsForLayoutUpdates removeAllObjects];

let nodesSizeChanged = [[NSMutableArray<ASCellNode *> alloc] init];
const auto nodesSizeChanged = [[NSMutableArray<ASCellNode *> alloc] init];
[_dataController relayoutNodes:nodes nodesSizeChanged:nodesSizeChanged];
if (nodesSizeChanged.count > 0) {
[self requeryNodeHeights];
Expand Down
4 changes: 2 additions & 2 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
[self setNeedsDisplay];

// Accessiblity
let currentAttributedText = self.attributedText; // Grab attributed string again in case it changed in the meantime
const auto currentAttributedText = self.attributedText; // Grab attributed string again in case it changed in the meantime
self.accessibilityLabel = self.defaultAccessibilityLabel;
self.isAccessibilityElement = (currentAttributedText.length != 0); // We're an accessibility element by default if there is a string.

Expand Down Expand Up @@ -883,7 +883,7 @@ - (NSArray *)_rectsForTextRange:(NSRange)textRange measureOption:(ASTextKitRende
ASLockScopeSelf();

NSArray *rects = [[self _locked_renderer] rectsForTextRange:textRange measureOption:measureOption];
let adjustedRects = [[NSMutableArray<NSValue *> alloc] init];
const auto adjustedRects = [[NSMutableArray<NSValue *> alloc] init];

for (NSValue *rectValue in rects) {
CGRect rect = [rectValue CGRectValue];
Expand Down
2 changes: 1 addition & 1 deletion Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ @implementation ASTextCacheValue

CGRect containerBounds = (CGRect){ .size = container.size };
{
for (let &t : cacheValue->_layouts) {
for (const auto &t : cacheValue->_layouts) {
CGSize constrainedSize = std::get<0>(t);
ASTextLayout *layout = std::get<1>(t);

Expand Down
4 changes: 2 additions & 2 deletions Source/ASVideoPlayerNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ - (void)createControls

{
ASUnlockScope(self);
for (var subnode : subnodes) {
for (ASDisplayNode *subnode : subnodes) {
[self addSubnode:subnode];
}
}
Expand Down Expand Up @@ -661,7 +661,7 @@ - (void)showSpinner
}];
_spinnerNode.style.preferredSize = CGSizeMake(44.0, 44.0);

let spinnerNode = _spinnerNode;
const auto spinnerNode = _spinnerNode;
{
ASUnlockScope(self);
[self addSubnode:spinnerNode];
Expand Down
Loading