Revision: 28636
          http://sourceforge.net/p/bibdesk/svn/28636
Author:   hofman
Date:     2024-01-21 17:34:04 +0000 (Sun, 21 Jan 2024)
Log Message:
-----------
use some NS collections instead of CF collections with custom callbacks

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.mm
    trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h      2024-01-21 
17:00:31 UTC (rev 28635)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h      2024-01-21 
17:34:04 UTC (rev 28636)
@@ -215,7 +215,7 @@
     NSMutableArray                 *_orderedSubtitles;
     NSMutableDictionary            *_iconCache;
     NSMutableDictionary            *_zombieIconCache;
-    CFMutableDictionaryRef          _infoTable;
+    NSMapTable                     *_infoTable;
     NSUInteger                      _numberOfColumns;
     NSUInteger                      _numberOfRows;
     NSColor                        *_backgroundColor;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2024-01-21 
17:00:31 UTC (rev 28635)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2024-01-21 
17:34:04 UTC (rev 28636)
@@ -363,16 +363,12 @@
     // created lazily when URLs are loaded
     _accessibilityIcons = nil;
     
-    CFAllocatorRef alloc = CFAllocatorGetDefault();
-    
     /*
      This avoids doing file operations on every URL while drawing, just to get 
the name and label.  
-     This table is purged by -reload, so we can use pointer keys and avoid 
hashing CFURL instances 
-     (and avoid copying keys...be sure to use CF to add values!).
+     This table is purged by -reload, so we can use pointer keys and avoid 
hashing NSURL instances
+     (and avoid copying keys).
      */
-    const CFDictionaryKeyCallBacks pointerKeyCallBacks = { 0, 
kCFTypeDictionaryKeyCallBacks.retain, kCFTypeDictionaryKeyCallBacks.release,
-                                                            
kCFTypeDictionaryKeyCallBacks.copyDescription, NULL, NULL };
-    _infoTable = CFDictionaryCreateMutable(alloc, 0, &pointerKeyCallBacks, 
&kCFTypeDictionaryValueCallBacks);        
+    _infoTable = [[NSMapTable alloc] 
initWithKeyOptions:NSPointerFunctionsObjectPointerPersonality | 
NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsObjectPersonality 
| NSPointerFunctionsStrongMemory capacity:0];
     
     // I'm not removing the timer in viewWillMoveToSuperview:nil because we 
may need to free up that memory, and the frequency is so low that it's 
insignificant overhead
     CFAbsoluteTime fireTime = CFAbsoluteTimeGetCurrent() + 
ZOMBIE_TIMER_INTERVAL;
@@ -467,7 +463,6 @@
     [self _invalidateProgressTimer];
     CFRunLoopTimerInvalidate(_zombieTimer);
     CFRelease(_zombieTimer);
-    CFRelease(_infoTable);
     // this variable is accessed in super's dealloc, so set it to NULL
     _trackingAreas = nil;
     _topSliderArea = nil;
@@ -851,10 +846,10 @@
 
 - (void)_getDisplayName:(NSString **)name andLabel:(NSUInteger *)label 
forURL:(NSURL *)aURL;
 {
-    _FVURLInfo *info = [(__bridge id)_infoTable objectForKey:aURL];
+    _FVURLInfo *info = [_infoTable objectForKey:aURL];
     if (nil == info) {
         info = [[_FVURLInfo alloc] initWithURL:aURL];
-        CFDictionarySetValue(_infoTable, (__bridge CFURLRef)aURL, (__bridge 
void *)info);
+        [_infoTable setObject:info forKey:aURL];
     }
     if (name) *name = [info name];
     if (label) *label = [info label];
@@ -1779,7 +1774,7 @@
     [_orderedIcons removeAllObjects];
     [_orderedSubtitles removeAllObjects];
     
-    CFDictionaryRemoveAllValues(_infoTable);
+    [_infoTable removeAllObjects];
     
     // datasource URL method
     SEL URLSel = @selector(fileView:URLAtIndex:);
@@ -1872,8 +1867,8 @@
 
 - (void)_handleFinderLabelChanged:(NSNotification *)note {
     NSURL *url = [note object];
-    if (CFDictionaryContainsKey(_infoTable, (__bridge void *)url)) {
-        CFDictionaryRemoveValue(_infoTable, (__bridge void *)url);
+    if ([_infoTable objectForKey:url]) {
+        [_infoTable removeObjectForKey:url];
         [self setNeedsDisplay:YES];
     }
 }

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m       2024-01-21 
17:00:31 UTC (rev 28635)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPDFIcon.m       2024-01-21 
17:34:04 UTC (rev 28636)
@@ -81,7 +81,7 @@
  yet only 80 have been marked as releaseable?  If the split is 100, 
-oldObjects always
  returns an empty set, but it keeps getting called repeatedly.  The split 
value, then,
  should always be less than (MAX_MAPPED_PROVIDER_COUNT / 2) to avoid wasted 
calls to
- -copyOldObjects and -removeOldObjects.
+ -oldObjects and -removeOldObjects.
 */
 + (void)_addIconForMappedRelease:(FVPDFIcon *)anIcon;
 {
@@ -91,18 +91,18 @@
         _releaseableIcons = [[_FVSplitSet alloc] initWithSplit:split];
     }
     [_releaseableIcons addObject:anIcon];
-    NSSet *oldObjects = nil;
+    NSHashTable *oldObjects = nil;
     // ??? is the second condition really required?
     if ([_FVMappedDataProvider maxSizeExceeded] || [_releaseableIcons count] 
>= [_releaseableIcons split] * 2) {
-        // copy inside the lock, then perform the slower 
makeObjectsPerformSelector: operation outside of it
-        oldObjects = [_releaseableIcons copyOldObjects];
+        // copy inside the lock, then perform the slower 
_releaseMappedResources operations outside of it
+        oldObjects = [_releaseableIcons oldObjects];
         // remove the first 100 objects, since the recently added ones are 
more likely to be needed again (scrolling up and down)
         [_releaseableIcons removeOldObjects];
     }
     pthread_mutex_unlock(&_releaseLock);
     
-    if ([oldObjects count])
-        [oldObjects 
makeObjectsPerformSelector:@selector(_releaseMappedResources)];
+    for (FVPDFIcon *oldIcon in oldObjects)
+        [oldIcon _releaseMappedResources];
 }
 
 + (void)_removeIconForMappedRelease:(FVPDFIcon *)anIcon;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.h 2024-01-21 
17:00:31 UTC (rev 28635)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.h 2024-01-21 
17:34:04 UTC (rev 28636)
@@ -59,7 +59,7 @@
 @interface FVPriorityQueue : NSObject <NSFastEnumeration>
 {
 @private;
-    CFMutableSetRef         _set;
+    NSMutableSet           *_set;
     id __unsafe_unretained *_values;
     NSUInteger              _count;
     NSUInteger              _capacity;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.mm
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.mm        
2024-01-21 17:00:31 UTC (rev 28635)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPriorityQueue.mm        
2024-01-21 17:34:04 UTC (rev 28636)
@@ -129,7 +129,7 @@
                 
         // queue does not retain its objects, so always add/remove from the 
set last
         
-        _set = CFSetCreateMutable(CFAllocatorGetDefault(), 0, 
&kCFTypeSetCallBacks);
+        _set = [[NSMutableSet alloc] init];
         
         capacity = __FVPriorityQueueRoundUpCapacity(capacity);
         _values = (id __unsafe_unretained *)NSZoneCalloc(NULL, capacity, 
sizeof(id));
@@ -139,7 +139,7 @@
         _sorted = NO;
         _mutations = 0;
         
-        if (NULL == _values || NULL == _set) {
+        if (NULL == _values || nil == _set) {
             self = nil;
         }
         
@@ -151,7 +151,6 @@
 
 - (void)dealloc
 {
-    if (_set) CFRelease(_set);
     NSZoneFree(NULL, _values);
 }
 
@@ -158,8 +157,8 @@
 - (void)push:(id)object;
 { 
     NSParameterAssert([object respondsToSelector:@selector(compare:)]);
-    if (CFSetContainsValue(_set, (__bridge void *)object) == FALSE) {
-        CFSetAddValue(_set, (__bridge void *)object);
+    if ([_set containsObject:object] == NO) {
+        [_set addObject:object];
         NSUInteger count = __FVPriorityQueueCount(self);
         count++;
         __FVPriorityQueueSetCount(self, count);
@@ -173,7 +172,7 @@
         _mutations++;
         _sorted = NO;
     }
-    NSAssert(self->_count == (NSUInteger)CFSetGetCount(self->_set), @"set and 
queue must have the same count");
+    NSAssert(self->_count == [self->_set count], @"set and queue must have the 
same count");
 }
 
 - (void)_makeHeap
@@ -213,8 +212,8 @@
     for (i = 0; i < iMax; i++) {
         id object = reinterpret_cast <id>(const_cast <void 
*>(CFArrayGetValueAtIndex(cfObjects, i)));
         NSParameterAssert([object respondsToSelector:@selector(compare:)]);
-        if (CFSetContainsValue(_set, (__bridge void *)object) == FALSE) {
-            CFSetAddValue(_set, (__bridge void *)object);
+        if ([_set containsObject:object] == NO) {
+            [_set addObject:object];
             buffer[numberAdded] = object;
             numberAdded++;
         }
@@ -233,7 +232,7 @@
         _mutations++;
     }
     if (stackBuf != buffer) delete buffer;
-    NSAssert(self->_count == (NSUInteger)CFSetGetCount(self->_set), @"set and 
queue must have the same count");
+    NSAssert(self->_count == [self->_set count], @"set and queue must have the 
same count");
 }
 
 - (id)pop;
@@ -254,7 +253,7 @@
         
         // make sure we don't remove the last reference to this object?
         toReturn = toReturn;
-        CFSetRemoveValue(_set, (__bridge void *)toReturn);
+        [_set removeObject:toReturn];
         
         if (0 == count)
             _madeHeap = 0;
@@ -261,13 +260,13 @@
         
         _mutations++;
     }
-    NSAssert(self->_count == (NSUInteger)CFSetGetCount(self->_set), @"set and 
queue must have the same count");
+    NSAssert(self->_count == (NSUInteger)[self->_set count], @"set and queue 
must have the same count");
     return toReturn;
 }
 
 - (void)removeAllObjects
 {
-    CFSetRemoveAllValues(_set);
+    [_set removeAllObjects];
     __FVPriorityQueueSetCount(self, 0);
     _madeHeap = NO;
     _mutations++;
@@ -319,7 +318,7 @@
 
 - (NSUInteger)count;
 { 
-    NSAssert(self->_count == (NSUInteger)CFSetGetCount(self->_set), @"set and 
queue must have the same count");
+    NSAssert(self->_count == [self->_set count], @"set and queue must have the 
same count");
     return __FVPriorityQueueCount(self);
 }
 

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.h     2024-01-21 
17:00:31 UTC (rev 28635)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.h     2024-01-21 
17:34:04 UTC (rev 28636)
@@ -41,8 +41,8 @@
 
 @interface _FVSplitSet : NSObject
 {
-    CFMutableSetRef _old;
-    CFMutableSetRef _new;
+    NSHashTable    *_old;
+    NSHashTable    *_new;
     NSUInteger      _split;
 }
 
@@ -51,7 +51,7 @@
 - (void)addObject:(id)obj;
 - (void)removeObject:(id)obj;
 - (void)removeOldObjects;
-- (NSSet *)copyOldObjects;
-- (NSUInteger)count;
+@property (nonatomic, readonly) NSHashTable *oldObjects;
+@property (nonatomic, readonly) NSUInteger count;
 
 @end

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.m     2024-01-21 
17:00:31 UTC (rev 28635)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/_FVSplitSet.m     2024-01-21 
17:34:04 UTC (rev 28636)
@@ -42,6 +42,7 @@
 @implementation _FVSplitSet
 
 @synthesize split=_split;
+@dynamic count, oldObjects;
 
 - (id)initWithSplit:(NSUInteger)split
 {
@@ -48,8 +49,8 @@
     NSParameterAssert(split > 0);
     self = [super init];
     if (self) {
-        _old = CFSetCreateMutable(CFAllocatorGetDefault(), 0, NULL);
-        _new = CFSetCreateMutable(CFAllocatorGetDefault(), split, NULL);
+        _old = [[NSHashTable alloc] 
initWithOptions:NSPointerFunctionsObjectPointerPersonality | 
NSPointerFunctionsStrongMemory capacity:0];
+        _new = [[NSHashTable alloc] 
initWithOptions:NSPointerFunctionsObjectPointerPersonality | 
NSPointerFunctionsStrongMemory capacity:split];
         _split = split;
     }
     return self;
@@ -59,24 +60,24 @@
 
 - (void)addObject:(id)obj
 {
-    if (_split == (NSUInteger)CFSetGetCount(_new)) {
-        [(__bridge NSMutableSet *)_old unionSet:(__bridge NSSet *)_new];
-        CFSetRemoveAllValues(_new);
+    if (_split == [_new count]) {
+        [_old unionHashTable:_new];
+        [_new removeAllObjects];
     }
-    CFSetAddValue(_new, (__bridge void *)obj);
-    CFSetRemoveValue(_old, (__bridge void *)obj);
+    [_new addObject:obj];
+    [_old removeObject:obj];
 }
 
 - (void)removeObject:(id)obj
 {
-    CFSetRemoveValue(_new, (__bridge void *)obj);
-    CFSetRemoveValue(_old, (__bridge void *)obj);
+    [_new removeObject:obj];
+    [_old removeObject:obj];
 }
 
-- (void)removeOldObjects { CFSetRemoveAllValues(_old); }
+- (void)removeOldObjects { [_old removeAllObjects]; }
 
-- (NSSet *)copyOldObjects { return (NSSet 
*)CFBridgingRelease(CFSetCreateCopy(CFGetAllocator(_old), _old)); }
+- (NSHashTable *)oldObjects { return [_old copy]; }
 
-- (NSUInteger)count { return CFSetGetCount(_old) + CFSetGetCount(_new); }
+- (NSUInteger)count { return [_old count] + [_new count]; }
 
 @end

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