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
This commit is contained in:
Eric Warmenhoven 2024-08-15 18:26:51 -04:00 committed by GitHub
parent a759e60148
commit 833bf2e616
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 7 deletions

View File

@ -771,8 +771,8 @@ void *cocoa_screen_get_chosen(void)
bool cocoa_has_focus(void *data) bool cocoa_has_focus(void *data)
{ {
#if defined(HAVE_COCOATOUCH) #if defined(HAVE_COCOATOUCH)
return ([[UIApplication sharedApplication] applicationState] /* if we are running, we are foregrounded */
== UIApplicationStateActive); return true;
#else #else
return [NSApp isActive]; return [NSApp isActive];
#endif #endif

View File

@ -186,12 +186,18 @@ apple_frontend_settings_t apple_frontend_settings;
void get_ios_version(int *major, int *minor) 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) dispatch_once(&onceToken, ^ {
*major = (int)[decomposed_os_version[0] integerValue]; NSArray *decomposed_os_version = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if (minor && decomposed_os_version.count > 1) if (decomposed_os_version.count > 0)
*minor = (int)[decomposed_os_version[1] integerValue]; 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 */ /* Input helpers: This is kept here because it needs ObjC */