Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 4ca97e2

Browse files
author
Scott Goodson
committed
Optimize string handling for CALayer gravity & UIView content mode. Finally fix protocol rename.
1 parent f902b4b commit 4ca97e2

2 files changed

Lines changed: 14 additions & 22 deletions

File tree

AsyncDisplayKit/ASTableView.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@
277277
/**
278278
* This is a node-based UITableViewDataSource.
279279
*/
280-
#define ASTableViewDataSource ASTableDataSource
281280
@protocol ASTableDataSource <ASCommonTableViewDataSource, NSObject>
282281

283282
/**
@@ -315,14 +314,15 @@
315314

316315
@end
317316

317+
@protocol ASTableViewDataSource <ASTableDataSource>
318+
@end
318319

319320
/**
320321
* This is a node-based UITableViewDelegate.
321322
*
322323
* Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are
323324
* responsible for deciding their preferred onscreen height in -calculateSizeThatFits:.
324325
*/
325-
#define ASTableViewDelegate ASTableDelegate
326326
@protocol ASTableDelegate <ASCommonTableViewDelegate, NSObject>
327327

328328
@optional
@@ -357,4 +357,7 @@
357357
*/
358358
- (BOOL)shouldBatchFetchForTableView:(ASTableView *)tableView;
359359

360-
@end
360+
@end
361+
362+
@protocol ASTableViewDelegate <ASTableDelegate>;
363+
@end

AsyncDisplayKit/Private/_ASCoreAnimationExtras.mm

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
#import "_ASCoreAnimationExtras.h"
10-
10+
#import "ASEqualityHelpers.h"
1111
#import "ASAssert.h"
1212

1313
extern void ASDisplayNodeSetupLayerContentsWithResizableImage(CALayer *layer, UIImage *image)
@@ -87,7 +87,8 @@ extern void ASDisplayNodeSetupLayerContentsWithResizableImage(CALayer *layer, UI
8787
{UIViewContentModeBottomRight, @"bottomRight"},
8888
};
8989

90-
NSString *ASDisplayNodeNSStringFromUIContentMode(UIViewContentMode contentMode) {
90+
NSString *ASDisplayNodeNSStringFromUIContentMode(UIViewContentMode contentMode)
91+
{
9192
for (int i=0; i< ARRAY_COUNT(UIContentModeDescriptionLUT); i++) {
9293
if (UIContentModeDescriptionLUT[i].contentMode == contentMode) {
9394
return UIContentModeDescriptionLUT[i].string;
@@ -96,16 +97,10 @@ extern void ASDisplayNodeSetupLayerContentsWithResizableImage(CALayer *layer, UI
9697
return [NSString stringWithFormat:@"%d", (int)contentMode];
9798
}
9899

99-
UIViewContentMode ASDisplayNodeUIContentModeFromNSString(NSString *string) {
100-
// If you passed one of the constants (this is just an optimization to avoid string comparison)
101-
for (int i=0; i < ARRAY_COUNT(UIContentModeDescriptionLUT); i++) {
102-
if (UIContentModeDescriptionLUT[i].string == string) {
103-
return UIContentModeDescriptionLUT[i].contentMode;
104-
}
105-
}
106-
// If you passed something isEqualToString: to one of the constants
100+
UIViewContentMode ASDisplayNodeUIContentModeFromNSString(NSString *string)
101+
{
107102
for (int i=0; i < ARRAY_COUNT(UIContentModeDescriptionLUT); i++) {
108-
if ([UIContentModeDescriptionLUT[i].string isEqualToString:string]) {
103+
if (ASObjectIsEqual(UIContentModeDescriptionLUT[i].string, string)) {
109104
return UIContentModeDescriptionLUT[i].contentMode;
110105
}
111106
}
@@ -126,18 +121,12 @@ UIViewContentMode ASDisplayNodeUIContentModeFromNSString(NSString *string) {
126121

127122
UIViewContentMode ASDisplayNodeUIContentModeFromCAContentsGravity(NSString *const contentsGravity)
128123
{
129-
// If you passed one of the constants (this is just an optimization to avoid string comparison)
130-
for (int i=0; i < ARRAY_COUNT(UIContentModeCAGravityLUT); i++) {
131-
if (UIContentModeCAGravityLUT[i].string == contentsGravity) {
132-
return UIContentModeCAGravityLUT[i].contentMode;
133-
}
134-
}
135-
// If you passed something isEqualToString: to one of the constants
136124
for (int i=0; i < ARRAY_COUNT(UIContentModeCAGravityLUT); i++) {
137-
if ([UIContentModeCAGravityLUT[i].string isEqualToString:contentsGravity]) {
125+
if (ASObjectIsEqual(UIContentModeCAGravityLUT[i].string, contentsGravity)) {
138126
return UIContentModeCAGravityLUT[i].contentMode;
139127
}
140128
}
129+
141130
ASDisplayNodeCAssert(contentsGravity, @"Encountered an unknown contentsGravity \"%@\". Is this a new version of iOS?", contentsGravity);
142131
ASDisplayNodeCAssert(!contentsGravity, @"You passed nil to ASDisplayNodeUIContentModeFromCAContentsGravity. We're falling back to resize, but this is probably a bug.");
143132
// If asserts disabled, fall back to this

0 commit comments

Comments
 (0)