From 41f05c73d8016efd2e343abd96d5ddc1016efa44 Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Mon, 18 Dec 2023 02:07:17 +0400 Subject: [PATCH] Cache resolved app bundle --- .../AppBundle/Sources/AppBundle/AppBundle.m | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/submodules/AppBundle/Sources/AppBundle/AppBundle.m b/submodules/AppBundle/Sources/AppBundle/AppBundle.m index 66f5e08fc8..e93a19a70d 100644 --- a/submodules/AppBundle/Sources/AppBundle/AppBundle.m +++ b/submodules/AppBundle/Sources/AppBundle/AppBundle.m @@ -1,15 +1,21 @@ #import NSBundle * _Nonnull getAppBundle() { - NSBundle *bundle = [NSBundle mainBundle]; - if ([[bundle.bundleURL pathExtension] isEqualToString:@"appex"]) { - bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]]; - } else if ([[bundle.bundleURL pathExtension] isEqualToString:@"framework"]) { - bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]]; - } else if ([[bundle.bundleURL pathExtension] isEqualToString:@"Frameworks"]) { - bundle = [NSBundle bundleWithURL:[bundle.bundleURL URLByDeletingLastPathComponent]]; - } - return bundle; + static NSBundle *appBundle = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSBundle *bundle = [NSBundle mainBundle]; + if ([[bundle.bundleURL pathExtension] isEqualToString:@"appex"]) { + bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]]; + } else if ([[bundle.bundleURL pathExtension] isEqualToString:@"framework"]) { + bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]]; + } else if ([[bundle.bundleURL pathExtension] isEqualToString:@"Frameworks"]) { + bundle = [NSBundle bundleWithURL:[bundle.bundleURL URLByDeletingLastPathComponent]]; + } + appBundle = bundle; + }); + + return appBundle; } @implementation UIImage (AppBundle)