Revision: 28498
          http://sourceforge.net/p/bibdesk/svn/28498
Author:   hofman
Date:     2024-01-01 11:12:19 +0000 (Mon, 01 Jan 2024)
Log Message:
-----------
create placeholder instance for class clusters in allocWithZone using 
dispatch_once

Modified Paths:
--------------
    trunk/bibdesk/BDSKBookmark.m
    trunk/bibdesk/BDSKLinkedFile.m
    trunk/bibdesk/BDSKSearchBookmark.m

Modified: trunk/bibdesk/BDSKBookmark.m
===================================================================
--- trunk/bibdesk/BDSKBookmark.m        2024-01-01 11:03:44 UTC (rev 28497)
+++ trunk/bibdesk/BDSKBookmark.m        2024-01-01 11:12:19 UTC (rev 28498)
@@ -80,17 +80,24 @@
 @synthesize parent;
 @dynamic dictionaryValue, bookmarkType, URL, name, icon, URLDescription;
 
-static BDSKPlaceholderBookmark *defaultPlaceholderBookmark = nil;
 static Class BDSKBookmarkClass = Nil;
 
 + (void)initialize {
     BDSKINITIALIZE;
     BDSKBookmarkClass = self;
-    defaultPlaceholderBookmark = (BDSKPlaceholderBookmark 
*)NSAllocateObject([BDSKPlaceholderBookmark class], 0, NSDefaultMallocZone());
 }
 
 + (id)allocWithZone:(NSZone *)aZone {
-    return BDSKBookmarkClass == self ? defaultPlaceholderBookmark : [super 
allocWithZone:aZone];
+    if (BDSKBookmarkClass == self) {
+        static BDSKPlaceholderBookmark *defaultPlaceholderBookmark = nil;
+        static dispatch_once_t onceToken = 0;
+        dispatch_once(&onceToken, ^{
+            defaultPlaceholderBookmark = [BDSKPlaceholderBookmark alloc];
+        });
+        return defaultPlaceholderBookmark;
+    } else {
+        return [super allocWithZone:aZone];
+    }
 }
 
 + (id)bookmarkWithURL:(NSURL *)aURL name:(NSString *)aName {

Modified: trunk/bibdesk/BDSKLinkedFile.m
===================================================================
--- trunk/bibdesk/BDSKLinkedFile.m      2024-01-01 11:03:44 UTC (rev 28497)
+++ trunk/bibdesk/BDSKLinkedFile.m      2024-01-01 11:12:19 UTC (rev 28498)
@@ -127,7 +127,6 @@
 
 @dynamic URL, file, displayURL, path, stringValue, bibTeXString, relativePath, 
delegate, hasSkimNotes;
 
-static BDSKPlaceholderLinkedFile *defaultPlaceholderLinkedFile = nil;
 static Class BDSKLinkedFileClass = Nil;
 static BOOL saveRelativePathOnly = NO;
 static BOOL saveArchivedData = NO;
@@ -138,7 +137,6 @@
 + (void)initialize {
     BDSKINITIALIZE;
     BDSKLinkedFileClass = self;
-    defaultPlaceholderLinkedFile = (BDSKPlaceholderLinkedFile 
*)NSAllocateObject([BDSKPlaceholderLinkedFile class], 0, NSDefaultMallocZone());
     saveRelativePathOnly = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKSaveLinkedFilesAsRelativePathOnlyKey];
     saveArchivedData = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKSaveLinkedFilesAsArchivedDataKey];
     wantsBookmark = saveArchivedData == NO && [[NSUserDefaults 
standardUserDefaults] boolForKey:BDSKSaveLinkedFilesAsBookmarkDataKey];
@@ -152,7 +150,16 @@
 }
 
 + (id)allocWithZone:(NSZone *)aZone {
-    return BDSKLinkedFileClass == self ? defaultPlaceholderLinkedFile : 
NSAllocateObject(self, 0, aZone);
+    if (BDSKLinkedFileClass == self) {
+        static BDSKPlaceholderLinkedFile *defaultPlaceholderLinkedFile = nil;
+        static dispatch_once_t onceToken = 0;
+        dispatch_once(&onceToken, ^{
+            defaultPlaceholderLinkedFile = [BDSKPlaceholderLinkedFile alloc];
+        });
+        return defaultPlaceholderLinkedFile;
+    } else {
+        return [super allocWithZone:aZone];
+    }
 }
 
 + (id)linkedFileWithURL:(NSURL *)aURL 
delegate:(id<BDSKLinkedFileDelegate>)aDelegate {

Modified: trunk/bibdesk/BDSKSearchBookmark.m
===================================================================
--- trunk/bibdesk/BDSKSearchBookmark.m  2024-01-01 11:03:44 UTC (rev 28497)
+++ trunk/bibdesk/BDSKSearchBookmark.m  2024-01-01 11:12:19 UTC (rev 28498)
@@ -77,17 +77,24 @@
 @synthesize parent;
 @dynamic dictionaryValue, bookmarkType, info, label, icon, name, searchTerm;
 
-static BDSKPlaceholderSearchBookmark *defaultPlaceholderSearchBookmark = nil;
 static Class BDSKSearchBookmarkClass = Nil;
 
 + (void)initialize {
     BDSKINITIALIZE;
     BDSKSearchBookmarkClass = self;
-    defaultPlaceholderSearchBookmark = (BDSKPlaceholderSearchBookmark 
*)NSAllocateObject([BDSKPlaceholderSearchBookmark class], 0, 
NSDefaultMallocZone());
 }
 
 + (id)allocWithZone:(NSZone *)aZone {
-    return BDSKSearchBookmarkClass == self ? defaultPlaceholderSearchBookmark 
: [super allocWithZone:aZone];
+    if (BDSKSearchBookmarkClass == self) {
+        static BDSKSearchBookmark *defaultPlaceholderSearchBookmark = nil;
+        static dispatch_once_t onceToken = 0;
+        dispatch_once(&onceToken, ^{
+            defaultPlaceholderSearchBookmark = [BDSKPlaceholderSearchBookmark 
alloc];
+        });
+        return defaultPlaceholderSearchBookmark;
+    } else {
+        return [super allocWithZone:aZone];
+    }
 }
 
 + (id)searchBookmarkFolderWithLabel:(NSString *)aLabel {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to