Skip to content

Commit

Permalink
GREYCAAnimationDelegate optimization.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 336386511
  • Loading branch information
tirodkar authored and mobile-devx-github-bot committed Oct 9, 2020
1 parent 3a77028 commit ddf2911
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions AppFramework/Delegate/GREYCAAnimationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,50 @@ static id InstrumentSurrogateDelegate(id self, id delegate, SEL originalSelector
SEL swizzledSelector, IMP selfImplementation,
IMP delegateImplementation);

/**
* Animation did start selector for the animation delegate.
*/
static SEL gAnimationDidStartSelector;
/**
* Swizzled animation did start selector for the animation delegate.
*/
static SEL gSwizzledAnimationDidStartSelector;
/**
* Animation did stop selector for the animation delegate.
*/
static SEL gAnimationDidStopSelector;
/**
* Swizzled animation did stop selector for the animation delegate.
*/
static SEL gSwizzledAnimationDidStopSelector;

@implementation GREYCAAnimationDelegate

+ (void)initialize {
if (self == [GREYCAAnimationDelegate self]) {
gAnimationDidStartSelector = @selector(animationDidStart:);
gSwizzledAnimationDidStartSelector = @selector(greyswizzled_animationDidStart:);
gAnimationDidStopSelector = @selector(animationDidStop:finished:);
gSwizzledAnimationDidStopSelector = @selector(greyswizzled_animationDidStop:finished:);
}
}

+ (id)surrogateDelegateForDelegate:(id)delegate {
id outDelegate;
if (!delegate) {
// If the delegate is nil then create and return a new delegate.
outDelegate = [[self alloc] initInternal];
} else {
SEL animationDidStartSEL = @selector(animationDidStart:);
SEL greyAnimationDidStartSEL = @selector(greyswizzled_animationDidStart:);
SEL animationDidStopSEL = @selector(animationDidStop:finished:);
SEL greyAnimationDidStopSEL = @selector(greyswizzled_animationDidStop:finished:);
IMP animationDidStartInstance = [self instanceMethodForSelector:animationDidStartSEL];
IMP delegateAnimationDidStartInstance = [delegate methodForSelector:animationDidStartSEL];
IMP animationDidStopInstance = [self instanceMethodForSelector:animationDidStopSEL];
IMP delegateAnimationDidStopInstance = [delegate methodForSelector:animationDidStopSEL];
outDelegate =
InstrumentSurrogateDelegate(self, delegate, animationDidStartSEL, greyAnimationDidStartSEL,
animationDidStartInstance, delegateAnimationDidStartInstance);
outDelegate =
InstrumentSurrogateDelegate(self, outDelegate, animationDidStopSEL, greyAnimationDidStopSEL,
animationDidStopInstance, delegateAnimationDidStopInstance);
IMP animationDidStartInstance = [self instanceMethodForSelector:gAnimationDidStartSelector];
IMP delegateAnimationDidStartInstance = [delegate methodForSelector:gAnimationDidStartSelector];
IMP animationDidStopInstance = [self instanceMethodForSelector:gAnimationDidStopSelector];
IMP delegateAnimationDidStopInstance = [delegate methodForSelector:gAnimationDidStopSelector];
outDelegate = InstrumentSurrogateDelegate(
self, delegate, gAnimationDidStartSelector, gSwizzledAnimationDidStartSelector,
animationDidStartInstance, delegateAnimationDidStartInstance);
outDelegate = InstrumentSurrogateDelegate(
self, outDelegate, gAnimationDidStopSelector, gSwizzledAnimationDidStopSelector,
animationDidStopInstance, delegateAnimationDidStopInstance);
}
return outDelegate;
}
Expand Down

0 comments on commit ddf2911

Please sign in to comment.