Skip to content

Commit

Permalink
Remove dispatch_once from +load
Browse files Browse the repository at this point in the history
+load is only called once as-is.  Wrapping a dispatch_once around the method contents is just extra overhead for no gain.
  • Loading branch information
jslegendre committed Dec 19, 2022
1 parent 7f09b2b commit d19c668
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,17 @@ - (void) swizzleInstanceMethod:(SEL)origSelector withMethod:(SEL)newSelector

+ (void) load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// TODO: UINSview
// TODO: UINSview

if ([[PlaySettings shared] adaptiveDisplay]) {
[objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(frame) withMethod:@selector(hook_frame)];
[objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(bounds) withMethod:@selector(hook_bounds)];
[objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_size)];
}
[objc_getClass("_UIMenuBuilder") swizzleInstanceMethod:sel_getUid("initWithRootMenu:") withMethod:@selector(initWithRootMenuHook:)];
if ([[PlaySettings shared] adaptiveDisplay]) {
[objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(frame) withMethod:@selector(hook_frame)];
[objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(bounds) withMethod:@selector(hook_bounds)];
[objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_size)];
}

[objc_getClass("_UIMenuBuilder") swizzleInstanceMethod:sel_getUid("initWithRootMenu:") withMethod:@selector(initWithRootMenuHook:)];

[objc_getClass("IOSViewController") swizzleInstanceMethod:@selector(prefersPointerLocked) withMethod:@selector(hook_prefersPointerLocked)];
});
[objc_getClass("IOSViewController") swizzleInstanceMethod:@selector(prefersPointerLocked) withMethod:@selector(hook_prefersPointerLocked)];
}

bool menuWasCreated = false;
Expand Down

0 comments on commit d19c668

Please sign in to comment.