Simplify Override Checking, Only Do It When Assertions Are Enabled #trivial (#253)

* Simplify our override checking, only do it when assertions are enabled

* Move those functions under the ASSERTIONS_ENABLED check
This commit is contained in:
Adlai Holler 2017-05-11 11:42:15 -07:00 committed by GitHub
parent f2c85fdc32
commit 538a02f119
2 changed files with 6 additions and 12 deletions

View File

@ -118,6 +118,8 @@ _ASPendingState *ASDisplayNodeGetPendingState(ASDisplayNode *node)
return result; return result;
} }
#if ASDISPLAYNODE_ASSERTIONS_ENABLED
/** /**
* Returns ASDisplayNodeFlags for the given class/instance. instance MAY BE NIL. * Returns ASDisplayNodeFlags for the given class/instance. instance MAY BE NIL.
* *
@ -190,8 +192,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
+ (void)initialize + (void)initialize
{ {
[super initialize];
if (self != [ASDisplayNode class]) { if (self != [ASDisplayNode class]) {
// Subclasses should never override these. Use unused to prevent warnings // Subclasses should never override these. Use unused to prevent warnings
@ -229,7 +229,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
class_replaceMethod(self, @selector(_staticInitialize), staticInitialize, "v:@"); class_replaceMethod(self, @selector(_staticInitialize), staticInitialize, "v:@");
#if DEBUG
// Check if subnodes where modified during the creation of the layout // Check if subnodes where modified during the creation of the layout
if (self == [ASDisplayNode class]) { if (self == [ASDisplayNode class]) {
__block IMP originalLayoutSpecThatFitsIMP = ASReplaceMethodWithBlock(self, @selector(_locked_layoutElementThatFits:), ^(ASDisplayNode *_self, ASSizeRange sizeRange) { __block IMP originalLayoutSpecThatFitsIMP = ASReplaceMethodWithBlock(self, @selector(_locked_layoutElementThatFits:), ^(ASDisplayNode *_self, ASSizeRange sizeRange) {
@ -243,9 +242,8 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
return layoutElement; return layoutElement;
}); });
} }
#endif
} }
#endif
+ (void)load + (void)load
{ {

View File

@ -30,9 +30,7 @@ BOOL ASSubclassOverridesSelector(Class superclass, Class subclass, SEL selector)
if (superclass == subclass) return NO; // Even if the class implements the selector, it doesn't override itself. if (superclass == subclass) return NO; // Even if the class implements the selector, it doesn't override itself.
Method superclassMethod = class_getInstanceMethod(superclass, selector); Method superclassMethod = class_getInstanceMethod(superclass, selector);
Method subclassMethod = class_getInstanceMethod(subclass, selector); Method subclassMethod = class_getInstanceMethod(subclass, selector);
IMP superclassIMP = superclassMethod ? method_getImplementation(superclassMethod) : NULL; return (superclassMethod != subclassMethod);
IMP subclassIMP = subclassMethod ? method_getImplementation(subclassMethod) : NULL;
return (superclassIMP != subclassIMP);
} }
BOOL ASSubclassOverridesClassSelector(Class superclass, Class subclass, SEL selector) BOOL ASSubclassOverridesClassSelector(Class superclass, Class subclass, SEL selector)
@ -40,9 +38,7 @@ BOOL ASSubclassOverridesClassSelector(Class superclass, Class subclass, SEL sele
if (superclass == subclass) return NO; // Even if the class implements the selector, it doesn't override itself. if (superclass == subclass) return NO; // Even if the class implements the selector, it doesn't override itself.
Method superclassMethod = class_getClassMethod(superclass, selector); Method superclassMethod = class_getClassMethod(superclass, selector);
Method subclassMethod = class_getClassMethod(subclass, selector); Method subclassMethod = class_getClassMethod(subclass, selector);
IMP superclassIMP = superclassMethod ? method_getImplementation(superclassMethod) : NULL; return (superclassMethod != subclassMethod);
IMP subclassIMP = subclassMethod ? method_getImplementation(subclassMethod) : NULL;
return (superclassIMP != subclassIMP);
} }
IMP ASReplaceMethodWithBlock(Class c, SEL origSEL, id block) IMP ASReplaceMethodWithBlock(Class c, SEL origSEL, id block)