From 833bf2e616e661819f269ac6af41cf321a4862e4 Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Thu, 15 Aug 2024 18:26:51 -0400 Subject: [PATCH] iOS/tvOS: minor performance tweaks (#16882) - it's ok to sleep in the foreground - ios always has focus, otherwise it's not running - don't keep reparsing strings --- ui/drivers/cocoa/cocoa_common.m | 4 ++-- ui/drivers/ui_cocoatouch.m | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index eb4023a794..8a5cf0c4ae 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -771,8 +771,8 @@ void *cocoa_screen_get_chosen(void) bool cocoa_has_focus(void *data) { #if defined(HAVE_COCOATOUCH) - return ([[UIApplication sharedApplication] applicationState] - == UIApplicationStateActive); + /* if we are running, we are foregrounded */ + return true; #else return [NSApp isActive]; #endif diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 314a3afce7..d2eaf69772 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -186,12 +186,18 @@ apple_frontend_settings_t apple_frontend_settings; void get_ios_version(int *major, int *minor) { - NSArray *decomposed_os_version = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; + static int savedMajor, savedMinor; + static dispatch_once_t onceToken; - if (major && decomposed_os_version.count > 0) - *major = (int)[decomposed_os_version[0] integerValue]; - if (minor && decomposed_os_version.count > 1) - *minor = (int)[decomposed_os_version[1] integerValue]; + dispatch_once(&onceToken, ^ { + NSArray *decomposed_os_version = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; + if (decomposed_os_version.count > 0) + savedMajor = (int)[decomposed_os_version[0] integerValue]; + if (decomposed_os_version.count > 1) + savedMinor = (int)[decomposed_os_version[1] integerValue]; + }); + if (major) *major = savedMajor; + if (minor) *minor = savedMinor; } /* Input helpers: This is kept here because it needs ObjC */