Skip to content

Commit ddf2911

Browse files
tirodkarmobile-devx-github-bot
authored andcommitted
GREYCAAnimationDelegate optimization.
PiperOrigin-RevId: 336386511
1 parent 3a77028 commit ddf2911

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

AppFramework/Delegate/GREYCAAnimationDelegate.m

+36-14
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,50 @@ static id InstrumentSurrogateDelegate(id self, id delegate, SEL originalSelector
7070
SEL swizzledSelector, IMP selfImplementation,
7171
IMP delegateImplementation);
7272

73+
/**
74+
* Animation did start selector for the animation delegate.
75+
*/
76+
static SEL gAnimationDidStartSelector;
77+
/**
78+
* Swizzled animation did start selector for the animation delegate.
79+
*/
80+
static SEL gSwizzledAnimationDidStartSelector;
81+
/**
82+
* Animation did stop selector for the animation delegate.
83+
*/
84+
static SEL gAnimationDidStopSelector;
85+
/**
86+
* Swizzled animation did stop selector for the animation delegate.
87+
*/
88+
static SEL gSwizzledAnimationDidStopSelector;
89+
7390
@implementation GREYCAAnimationDelegate
7491

92+
+ (void)initialize {
93+
if (self == [GREYCAAnimationDelegate self]) {
94+
gAnimationDidStartSelector = @selector(animationDidStart:);
95+
gSwizzledAnimationDidStartSelector = @selector(greyswizzled_animationDidStart:);
96+
gAnimationDidStopSelector = @selector(animationDidStop:finished:);
97+
gSwizzledAnimationDidStopSelector = @selector(greyswizzled_animationDidStop:finished:);
98+
}
99+
}
100+
75101
+ (id)surrogateDelegateForDelegate:(id)delegate {
76102
id outDelegate;
77103
if (!delegate) {
78104
// If the delegate is nil then create and return a new delegate.
79105
outDelegate = [[self alloc] initInternal];
80106
} else {
81-
SEL animationDidStartSEL = @selector(animationDidStart:);
82-
SEL greyAnimationDidStartSEL = @selector(greyswizzled_animationDidStart:);
83-
SEL animationDidStopSEL = @selector(animationDidStop:finished:);
84-
SEL greyAnimationDidStopSEL = @selector(greyswizzled_animationDidStop:finished:);
85-
IMP animationDidStartInstance = [self instanceMethodForSelector:animationDidStartSEL];
86-
IMP delegateAnimationDidStartInstance = [delegate methodForSelector:animationDidStartSEL];
87-
IMP animationDidStopInstance = [self instanceMethodForSelector:animationDidStopSEL];
88-
IMP delegateAnimationDidStopInstance = [delegate methodForSelector:animationDidStopSEL];
89-
outDelegate =
90-
InstrumentSurrogateDelegate(self, delegate, animationDidStartSEL, greyAnimationDidStartSEL,
91-
animationDidStartInstance, delegateAnimationDidStartInstance);
92-
outDelegate =
93-
InstrumentSurrogateDelegate(self, outDelegate, animationDidStopSEL, greyAnimationDidStopSEL,
94-
animationDidStopInstance, delegateAnimationDidStopInstance);
107+
IMP animationDidStartInstance = [self instanceMethodForSelector:gAnimationDidStartSelector];
108+
IMP delegateAnimationDidStartInstance = [delegate methodForSelector:gAnimationDidStartSelector];
109+
IMP animationDidStopInstance = [self instanceMethodForSelector:gAnimationDidStopSelector];
110+
IMP delegateAnimationDidStopInstance = [delegate methodForSelector:gAnimationDidStopSelector];
111+
outDelegate = InstrumentSurrogateDelegate(
112+
self, delegate, gAnimationDidStartSelector, gSwizzledAnimationDidStartSelector,
113+
animationDidStartInstance, delegateAnimationDidStartInstance);
114+
outDelegate = InstrumentSurrogateDelegate(
115+
self, outDelegate, gAnimationDidStopSelector, gSwizzledAnimationDidStopSelector,
116+
animationDidStopInstance, delegateAnimationDidStopInstance);
95117
}
96118
return outDelegate;
97119
}

0 commit comments

Comments
 (0)