[Bf-blender-cvs] [96387a2eff9] master: Cleanup: const, autoreleasepool, remove unneeded cast.
Ankit Meel
noreply at git.blender.org
Sat Dec 11 14:37:48 CET 2021
Commit: 96387a2eff97709f519274aa510942c5eec6b493
Author: Ankit Meel
Date: Sat Dec 11 19:07:36 2021 +0530
Branches: master
https://developer.blender.org/rB96387a2eff97709f519274aa510942c5eec6b493
Cleanup: const, autoreleasepool, remove unneeded cast.
Early return in some places also.
De-duplicate getSystemDir and getUserDir also.
Reviewed By: #platform_macos, brecht
Differential Revision: https://developer.blender.org/D13211
===================================================================
M intern/ghost/intern/GHOST_SystemPathsCocoa.mm
===================================================================
diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm
index 43ce0bb0533..4032c145ab4 100644
--- a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm
@@ -36,130 +36,101 @@ GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa()
#pragma mark Base directories retrieval
-const char *GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const
+static const char *GetApplicationSupportDir(const char *versionstr,
+ const NSSearchPathDomainMask mask,
+ char *tempPath,
+ const std::size_t len_tempPath)
{
- static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
- NSArray *paths;
-
- paths = NSSearchPathForDirectoriesInDomains(
- NSApplicationSupportDirectory, NSLocalDomainMask, YES);
-
- if ([paths count] > 0)
- basePath = [paths objectAtIndex:0];
- else {
- [pool drain];
- return NULL;
- }
+ @autoreleasepool {
+ const NSArray *const paths = NSSearchPathForDirectoriesInDomains(
+ NSApplicationSupportDirectory, mask, YES);
- snprintf(tempPath,
- sizeof(tempPath),
- "%s/Blender/%s",
- [basePath cStringUsingEncoding:NSASCIIStringEncoding],
- versionstr);
-
- [pool drain];
+ if ([paths count] == 0) {
+ return NULL;
+ }
+ const NSString *const basePath = [paths objectAtIndex:0];
+
+ snprintf(tempPath,
+ len_tempPath,
+ "%s/Blender/%s",
+ [basePath cStringUsingEncoding:NSASCIIStringEncoding],
+ versionstr);
+ }
return tempPath;
}
-const char *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const
+const char *GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const
{
static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
- NSArray *paths;
-
- paths = NSSearchPathForDirectoriesInDomains(
- NSApplicationSupportDirectory, NSUserDomainMask, YES);
-
- if ([paths count] > 0)
- basePath = [paths objectAtIndex:0];
- else {
- [pool drain];
- return NULL;
- }
-
- snprintf(tempPath,
- sizeof(tempPath),
- "%s/Blender/%s",
- [basePath cStringUsingEncoding:NSASCIIStringEncoding],
- versionstr);
+ return GetApplicationSupportDir(versionstr, NSLocalDomainMask, tempPath, sizeof(tempPath));
+}
- [pool drain];
- return tempPath;
+const char *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const
+{
+ static char tempPath[512] = "";
+ return GetApplicationSupportDir(versionstr, NSUserDomainMask, tempPath, sizeof(tempPath));
}
const char *GHOST_SystemPathsCocoa::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
{
static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
- NSArray *paths;
- NSSearchPathDirectory ns_directory;
-
- switch (type) {
- case GHOST_kUserSpecialDirDesktop:
- ns_directory = NSDesktopDirectory;
- break;
- case GHOST_kUserSpecialDirDocuments:
- ns_directory = NSDocumentDirectory;
- break;
- case GHOST_kUserSpecialDirDownloads:
- ns_directory = NSDownloadsDirectory;
- break;
- case GHOST_kUserSpecialDirMusic:
- ns_directory = NSMusicDirectory;
- break;
- case GHOST_kUserSpecialDirPictures:
- ns_directory = NSPicturesDirectory;
- break;
- case GHOST_kUserSpecialDirVideos:
- ns_directory = NSMoviesDirectory;
- break;
- case GHOST_kUserSpecialDirCaches:
- ns_directory = NSCachesDirectory;
- break;
- default:
- GHOST_ASSERT(
- false,
- "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
- [pool drain];
+ @autoreleasepool {
+ NSSearchPathDirectory ns_directory;
+
+ switch (type) {
+ case GHOST_kUserSpecialDirDesktop:
+ ns_directory = NSDesktopDirectory;
+ break;
+ case GHOST_kUserSpecialDirDocuments:
+ ns_directory = NSDocumentDirectory;
+ break;
+ case GHOST_kUserSpecialDirDownloads:
+ ns_directory = NSDownloadsDirectory;
+ break;
+ case GHOST_kUserSpecialDirMusic:
+ ns_directory = NSMusicDirectory;
+ break;
+ case GHOST_kUserSpecialDirPictures:
+ ns_directory = NSPicturesDirectory;
+ break;
+ case GHOST_kUserSpecialDirVideos:
+ ns_directory = NSMoviesDirectory;
+ break;
+ case GHOST_kUserSpecialDirCaches:
+ ns_directory = NSCachesDirectory;
+ break;
+ default:
+ GHOST_ASSERT(
+ false,
+ "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
+ return NULL;
+ }
+
+ const NSArray *const paths = NSSearchPathForDirectoriesInDomains(
+ ns_directory, NSUserDomainMask, YES);
+ if ([paths count] == 0) {
return NULL;
- }
-
- paths = NSSearchPathForDirectoriesInDomains(ns_directory, NSUserDomainMask, YES);
+ }
+ const NSString *const basePath = [paths objectAtIndex:0];
- if ([paths count] > 0)
- basePath = [paths objectAtIndex:0];
- else {
- [pool drain];
- return NULL;
+ strncpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
}
-
- strncpy(
- (char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
-
- [pool drain];
return tempPath;
}
const char *GHOST_SystemPathsCocoa::getBinaryDir() const
{
static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
-
- basePath = [[NSBundle mainBundle] bundlePath];
- if (basePath == nil) {
- [pool drain];
- return NULL;
- }
+ @autoreleasepool {
+ const NSString *const basePath = [[NSBundle mainBundle] bundlePath];
- strcpy((char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
+ if (basePath == nil) {
+ return NULL;
+ }
- [pool drain];
+ strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
+ }
return tempPath;
}
More information about the Bf-blender-cvs
mailing list