Skip to content

Commit

Permalink
Simplify Override Checking, Only Do It When Assertions Are Enabled #t…
Browse files Browse the repository at this point in the history
…rivial (#253)

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

* Move those functions under the ASSERTIONS_ENABLED check
  • Loading branch information
Adlai-Holler committed May 11, 2017
1 parent f2c85fd commit 538a02f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
10 changes: 4 additions & 6 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ BOOL ASDisplayNodeNeedsSpecialPropertiesHandling(BOOL isSynchronous, BOOL isLaye
return result;
}

#if ASDISPLAYNODE_ASSERTIONS_ENABLED

/**
* Returns ASDisplayNodeFlags for the given class/instance. instance MAY BE NIL.
*
Expand Down Expand Up @@ -190,8 +192,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)

+ (void)initialize
{
[super initialize];

if (self != [ASDisplayNode class]) {

// Subclasses should never override these. Use unused to prevent warnings
Expand Down Expand Up @@ -228,8 +228,7 @@ + (void)initialize

class_replaceMethod(self, @selector(_staticInitialize), staticInitialize, "v:@");


#if DEBUG

// Check if subnodes where modified during the creation of the layout
if (self == [ASDisplayNode class]) {
__block IMP originalLayoutSpecThatFitsIMP = ASReplaceMethodWithBlock(self, @selector(_locked_layoutElementThatFits:), ^(ASDisplayNode *_self, ASSizeRange sizeRange) {
Expand All @@ -243,9 +242,8 @@ + (void)initialize
return layoutElement;
});
}
#endif

}
#endif

+ (void)load
{
Expand Down
8 changes: 2 additions & 6 deletions Source/Private/ASInternalHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ 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.
Method superclassMethod = class_getInstanceMethod(superclass, selector);
Method subclassMethod = class_getInstanceMethod(subclass, selector);
IMP superclassIMP = superclassMethod ? method_getImplementation(superclassMethod) : NULL;
IMP subclassIMP = subclassMethod ? method_getImplementation(subclassMethod) : NULL;
return (superclassIMP != subclassIMP);
return (superclassMethod != subclassMethod);
}

BOOL ASSubclassOverridesClassSelector(Class superclass, Class subclass, SEL selector)
{
if (superclass == subclass) return NO; // Even if the class implements the selector, it doesn't override itself.
Method superclassMethod = class_getClassMethod(superclass, selector);
Method subclassMethod = class_getClassMethod(subclass, selector);
IMP superclassIMP = superclassMethod ? method_getImplementation(superclassMethod) : NULL;
IMP subclassIMP = subclassMethod ? method_getImplementation(subclassMethod) : NULL;
return (superclassIMP != subclassIMP);
return (superclassMethod != subclassMethod);
}

IMP ASReplaceMethodWithBlock(Class c, SEL origSEL, id block)
Expand Down

0 comments on commit 538a02f

Please sign in to comment.