Revision: 25410
          http://sourceforge.net/p/bibdesk/svn/25410
Author:   hofman
Date:     2021-01-16 10:54:59 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Use NSMapTable for maps with integer keys and/or values

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h      2021-01-16 
07:30:27 UTC (rev 25409)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h      2021-01-16 
10:54:59 UTC (rev 25410)
@@ -246,7 +246,7 @@
     NSPoint                  _lastOrigin;
     NSTextFieldCell         *_titleCell;
     NSTextFieldCell         *_subtitleCell;
-    CFMutableDictionaryRef   _trackingRectMap;
+    NSMapTable              *_trackingRectMap;
     NSButtonCell            *_leftArrow;
     NSButtonCell            *_rightArrow;
     NSRect                   _leftArrowFrame;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2021-01-16 
07:30:27 UTC (rev 25409)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2021-01-16 
10:54:59 UTC (rev 25410)
@@ -336,7 +336,7 @@
     
     _lastOrigin = NSZeroPoint;
     _timeOfLastOrigin = CFAbsoluteTimeGetCurrent();
-    _trackingRectMap = CFDictionaryCreateMutable(alloc, 0, 
&FVIntegerKeyDictionaryCallBacks, &FVIntegerValueDictionaryCallBacks);
+    _trackingRectMap = NSCreateMapTable(NSIntegerMapKeyCallBacks, 
NSIntegerMapValueCallBacks, 0);
     
     // @@ Dark mode
     
@@ -435,7 +435,7 @@
     [_backgroundColor release];
     [_sliderWindow release];
     // this variable is accessed in super's dealloc, so set it to NULL
-    CFRelease(_trackingRectMap);
+    NSFreeMapTable(_trackingRectMap);
     _trackingRectMap = NULL;
     // takes care of the timer as well
     [self _cancelDownloads];
@@ -1552,16 +1552,15 @@
 
 #pragma mark Layout and content updating
 
-static void _removeTrackingRectTagFromView(const void *key, const void *value, 
void *context)
-{
-    [(NSView *)context removeTrackingRect:(NSTrackingRectTag)key];
-}
-
 - (void)_removeAllTrackingRects
 {
     if (_trackingRectMap) {
-        CFDictionaryApplyFunction(_trackingRectMap, 
_removeTrackingRectTagFromView, self);
-        CFDictionaryRemoveAllValues(_trackingRectMap);
+        NSTrackingRectTag tag;
+        NSMapEnumerator enumerator = NSEnumerateMapTable(_trackingRectMap);
+        while (NSNextMapEnumeratorPair(&enumerator, (void **)&tag, NULL))
+            [self removeTrackingRect:tag];
+        NSEndMapTableEnumeration(&enumerator);
+        NSResetMapTable(_trackingRectMap);
     }
     if (-1 != _topSliderTag)
         [self removeTrackingRect:_topSliderTag];
@@ -1595,7 +1594,7 @@
                     
                     // Getting the location from the mouseEntered: event isn't 
reliable if you move the mouse slowly, so we either need to enlarge this 
tracking rect, or keep a map table of tag->index.  Since we have to keep a set 
of tags anyway, we'll use the latter method.
                     NSTrackingRectTag tag = [self addTrackingRect:iconRect 
owner:self userData:NULL assumeInside:mouseInside];
-                    CFDictionarySetValue(_trackingRectMap, (const void *)tag, 
(const void *)i);
+                    NSMapInsert(_trackingRectMap, (const void *)tag, (const 
void *)i);
                     
                     // don't pass the URL as owner, as it's not retained; use 
the delegate method instead
                     [self addToolTipRect:iconRect owner:self userData:NULL];
@@ -3126,7 +3125,8 @@
     
     // Finder doesn't show buttons unless it's the front app.  If Finder is 
the front app, it shows them for any window, regardless of main/key state, so 
we'll do the same.
     if ([NSApp isActive]) {
-        if (CFDictionaryGetValueIfPresent(_trackingRectMap, (const void *)tag, 
(const void **)&anIndex)) {
+        anIndex = (NSUInteger)NSMapGet(_trackingRectMap, (const void *)tag);
+        if (anIndex) {
             [self _showArrowsForIconAtIndex:anIndex];
         } else if (_fvFlags.displayMode == FVDisplayModeGrid && _sliderWindow 
&& [event userData] == _sliderWindow) {
             

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m   2021-01-16 
07:30:27 UTC (rev 25409)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m   2021-01-16 
10:54:59 UTC (rev 25410)
@@ -54,12 +54,12 @@
 
 @implementation FVFinderLabel
 
-static CFMutableDictionaryRef _layers = NULL;
+static NSMapTable *_layers = nil;
 
 + (void)initialize
 {
     FVINITIALIZE(FVFinderLabel);
-    _layers = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, 
&FVIntegerKeyDictionaryCallBacks, &kCFTypeDictionaryValueCallBacks);
+    _layers = NSCreateMapTable(NSIntegerMapKeyCallBacks, 
NSObjectMapValueCallBacks, 0);
 }
 
 typedef struct _FVRGBAColor { 
@@ -336,7 +336,7 @@
 
 + (CGLayerRef)_layerForLabel:(NSUInteger)label context:(CGContextRef)context
 {
-    CGLayerRef layer = (void *)CFDictionaryGetValue(_layers, (const void 
*)label);    
+    CGLayerRef layer = (CGLayerRef)NSMapGet(_layers, (const void *)label);
     if (NULL == layer) {
         CGSize layerSize = [self _layerSize];
         if (NULL == context)
@@ -345,7 +345,7 @@
         layer = CGLayerCreateWithContext(context, layerSize, NULL);
         CGContextRef layerContext = CGLayerGetContext(layer);
         [self _drawLabel:label inRect:NSMakeRect(0, 0, layerSize.width, 
layerSize.height) ofContext:layerContext];
-        CFDictionarySetValue(_layers, (const void *)label, layer);
+        NSMapInsert(_layers, (const void *)label, layer);
         CGLayerRelease(layer);
     }
     return layer;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.h     2021-01-16 
07:30:27 UTC (rev 25409)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.h     2021-01-16 
10:54:59 UTC (rev 25410)
@@ -45,14 +45,6 @@
 
 /** @file FVUtilities.h  Various useful functions. */
 
-/** @internal @var FVIntegerKeyDictionaryCallBacks
- For integer keys in a CFDictionary.  Do not use for toll-free bridging. */
-FV_EXTERN const CFDictionaryKeyCallBacks FVIntegerKeyDictionaryCallBacks;
-
-/** @internal @var FVIntegerValueDictionaryCallBacks
- For integer values in a CFDictionary.  Do not use for toll-free bridging. */
-FV_EXTERN const CFDictionaryValueCallBacks FVIntegerValueDictionaryCallBacks;
-
 /** @internal @var FVNSObjectSetCallBacks
  For NSObject subclasses in a CFSet.  Compatible with toll-free bridging. */
 FV_EXTERN const CFSetCallBacks FVNSObjectSetCallBacks;
@@ -62,13 +54,6 @@
  For NSObject subclasses in a CFSet using pointer equality.  Compatible with 
toll-free bridging. */
 FV_EXTERN const CFSetCallBacks FVNSObjectPointerSetCallBacks;
 
-/** @internal @brief For use with integer-valued dictionaries.
- @param dict CFDictionary with integer values.
- @param key Key of interest.
- @param value Pointer in which to return the value.
- @return TRUE if the key was present, FALSE if not present */  
-FV_PRIVATE_EXTERN Boolean FVCFDictionaryGetIntegerIfPresent(CFDictionaryRef 
dict, const void *key, NSInteger *value);
-
 /** @internal @brief Nonretaining timer.
  Creates a timer that does not retain its target; does not schedule the timer 
in a runloop.
  @param interval Fire interval.

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.m     2021-01-16 
07:30:27 UTC (rev 25409)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVUtilities.m     2021-01-16 
10:54:59 UTC (rev 25410)
@@ -39,10 +39,6 @@
 #import "FVUtilities.h"
 #import "zlib.h"
 
-static Boolean __FVIntegerEquality(const void *v1, const void *v2) { return v1 
== v2; }
-static CFStringRef __FVIntegerCopyDescription(const void *value) { return 
(CFStringRef)[[NSString alloc] initWithFormat:@"%ld", (long)value]; }
-static CFHashCode __FVIntegerHash(const void *value) { return 
(CFHashCode)value; }
-
 static CFStringRef __FVObjectCopyDescription(const void *value) { return 
(CFStringRef)[[(id)value description] copy]; }
 static CFHashCode __FVObjectHash(const void *value) { return [(id)value hash]; 
}
 static Boolean __FVObjectEqual(const void *value1, const void *value2) { 
return (Boolean)[(id)value1 isEqual:(id)value2]; }
@@ -49,21 +45,9 @@
 static const void * __FVObjectRetain(CFAllocatorRef alloc, const void *value) 
{ return [(id)value retain]; }
 static void __FVObjectRelease(CFAllocatorRef alloc, const void *value) { 
[(id)value release]; }
 
-const CFDictionaryKeyCallBacks FVIntegerKeyDictionaryCallBacks = { 0, NULL, 
NULL, __FVIntegerCopyDescription, __FVIntegerEquality, __FVIntegerHash };
-const CFDictionaryValueCallBacks FVIntegerValueDictionaryCallBacks = { 0, 
NULL, NULL, __FVIntegerCopyDescription, __FVIntegerEquality };
 const CFSetCallBacks FVNSObjectSetCallBacks = { 0, __FVObjectRetain, 
__FVObjectRelease, __FVObjectCopyDescription, __FVObjectEqual, __FVObjectHash };
 const CFSetCallBacks FVNSObjectPointerSetCallBacks = { 0, __FVObjectRetain, 
__FVObjectRelease, __FVObjectCopyDescription, NULL, NULL };
 
-Boolean FVCFDictionaryGetIntegerIfPresent(CFDictionaryRef dict, const void 
*key, NSInteger *value)
-{
-    union { const void *pv; const NSInteger iv; } u;
-    if (CFDictionaryGetValueIfPresent(dict, key, &u.pv)) {
-        *value = u.iv;
-        return TRUE;
-    }
-    return FALSE;
-}
-
 #pragma mark Timer
 
 // Object that can be retained and released by the timer, but does not retain 
its ivars

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