Optimize string handling for CALayer gravity & UIView content mode. Finally fix protocol rename.

This commit is contained in:
Scott Goodson
2015-12-24 23:13:50 -08:00
parent f902b4bdc7
commit 4ca97e2f4d
2 changed files with 14 additions and 22 deletions

View File

@@ -277,7 +277,6 @@
/** /**
* This is a node-based UITableViewDataSource. * This is a node-based UITableViewDataSource.
*/ */
#define ASTableViewDataSource ASTableDataSource
@protocol ASTableDataSource <ASCommonTableViewDataSource, NSObject> @protocol ASTableDataSource <ASCommonTableViewDataSource, NSObject>
/** /**
@@ -315,6 +314,8 @@
@end @end
@protocol ASTableViewDataSource <ASTableDataSource>
@end
/** /**
* This is a node-based UITableViewDelegate. * This is a node-based UITableViewDelegate.
@@ -322,7 +323,6 @@
* Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are * Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are
* responsible for deciding their preferred onscreen height in -calculateSizeThatFits:. * responsible for deciding their preferred onscreen height in -calculateSizeThatFits:.
*/ */
#define ASTableViewDelegate ASTableDelegate
@protocol ASTableDelegate <ASCommonTableViewDelegate, NSObject> @protocol ASTableDelegate <ASCommonTableViewDelegate, NSObject>
@optional @optional
@@ -357,4 +357,7 @@
*/ */
- (BOOL)shouldBatchFetchForTableView:(ASTableView *)tableView; - (BOOL)shouldBatchFetchForTableView:(ASTableView *)tableView;
@end @end
@protocol ASTableViewDelegate <ASTableDelegate>;
@end

View File

@@ -7,7 +7,7 @@
*/ */
#import "_ASCoreAnimationExtras.h" #import "_ASCoreAnimationExtras.h"
#import "ASEqualityHelpers.h"
#import "ASAssert.h" #import "ASAssert.h"
extern void ASDisplayNodeSetupLayerContentsWithResizableImage(CALayer *layer, UIImage *image) extern void ASDisplayNodeSetupLayerContentsWithResizableImage(CALayer *layer, UIImage *image)
@@ -87,7 +87,8 @@ static const struct _UIContentModeStringLUTEntry UIContentModeDescriptionLUT[] =
{UIViewContentModeBottomRight, @"bottomRight"}, {UIViewContentModeBottomRight, @"bottomRight"},
}; };
NSString *ASDisplayNodeNSStringFromUIContentMode(UIViewContentMode contentMode) { NSString *ASDisplayNodeNSStringFromUIContentMode(UIViewContentMode contentMode)
{
for (int i=0; i< ARRAY_COUNT(UIContentModeDescriptionLUT); i++) { for (int i=0; i< ARRAY_COUNT(UIContentModeDescriptionLUT); i++) {
if (UIContentModeDescriptionLUT[i].contentMode == contentMode) { if (UIContentModeDescriptionLUT[i].contentMode == contentMode) {
return UIContentModeDescriptionLUT[i].string; return UIContentModeDescriptionLUT[i].string;
@@ -96,16 +97,10 @@ NSString *ASDisplayNodeNSStringFromUIContentMode(UIViewContentMode contentMode)
return [NSString stringWithFormat:@"%d", (int)contentMode]; return [NSString stringWithFormat:@"%d", (int)contentMode];
} }
UIViewContentMode ASDisplayNodeUIContentModeFromNSString(NSString *string) { UIViewContentMode ASDisplayNodeUIContentModeFromNSString(NSString *string)
// If you passed one of the constants (this is just an optimization to avoid string comparison) {
for (int i=0; i < ARRAY_COUNT(UIContentModeDescriptionLUT); i++) { for (int i=0; i < ARRAY_COUNT(UIContentModeDescriptionLUT); i++) {
if (UIContentModeDescriptionLUT[i].string == string) { if (ASObjectIsEqual(UIContentModeDescriptionLUT[i].string, string)) {
return UIContentModeDescriptionLUT[i].contentMode;
}
}
// If you passed something isEqualToString: to one of the constants
for (int i=0; i < ARRAY_COUNT(UIContentModeDescriptionLUT); i++) {
if ([UIContentModeDescriptionLUT[i].string isEqualToString:string]) {
return UIContentModeDescriptionLUT[i].contentMode; return UIContentModeDescriptionLUT[i].contentMode;
} }
} }
@@ -126,18 +121,12 @@ NSString *const ASDisplayNodeCAContentsGravityFromUIContentMode(UIViewContentMod
UIViewContentMode ASDisplayNodeUIContentModeFromCAContentsGravity(NSString *const contentsGravity) UIViewContentMode ASDisplayNodeUIContentModeFromCAContentsGravity(NSString *const contentsGravity)
{ {
// If you passed one of the constants (this is just an optimization to avoid string comparison)
for (int i=0; i < ARRAY_COUNT(UIContentModeCAGravityLUT); i++) { for (int i=0; i < ARRAY_COUNT(UIContentModeCAGravityLUT); i++) {
if (UIContentModeCAGravityLUT[i].string == contentsGravity) { if (ASObjectIsEqual(UIContentModeCAGravityLUT[i].string, contentsGravity)) {
return UIContentModeCAGravityLUT[i].contentMode;
}
}
// If you passed something isEqualToString: to one of the constants
for (int i=0; i < ARRAY_COUNT(UIContentModeCAGravityLUT); i++) {
if ([UIContentModeCAGravityLUT[i].string isEqualToString:contentsGravity]) {
return UIContentModeCAGravityLUT[i].contentMode; return UIContentModeCAGravityLUT[i].contentMode;
} }
} }
ASDisplayNodeCAssert(contentsGravity, @"Encountered an unknown contentsGravity \"%@\". Is this a new version of iOS?", contentsGravity); ASDisplayNodeCAssert(contentsGravity, @"Encountered an unknown contentsGravity \"%@\". Is this a new version of iOS?", contentsGravity);
ASDisplayNodeCAssert(!contentsGravity, @"You passed nil to ASDisplayNodeUIContentModeFromCAContentsGravity. We're falling back to resize, but this is probably a bug."); ASDisplayNodeCAssert(!contentsGravity, @"You passed nil to ASDisplayNodeUIContentModeFromCAContentsGravity. We're falling back to resize, but this is probably a bug.");
// If asserts disabled, fall back to this // If asserts disabled, fall back to this