Revision: 25402
          http://sourceforge.net/p/bibdesk/svn/25402
Author:   hofman
Date:     2021-01-15 15:19:19 +0000 (Fri, 15 Jan 2021)
Log Message:
-----------
Use array to keep badge layers

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVAliasBadge.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPlaceholderImage.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVAliasBadge.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVAliasBadge.m    2021-01-15 
07:30:37 UTC (rev 25401)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVAliasBadge.m    2021-01-15 
15:19:19 UTC (rev 25402)
@@ -41,7 +41,7 @@
 
 @implementation FVAliasBadge
 
-static CFMutableDictionaryRef _badges = NULL;
+static NSMutableArray *_badges = nil;
 static const NSUInteger _sizes[] = { 32, 64, 128, 256, 512 };
 
 + (void)initialize
@@ -48,7 +48,7 @@
 {
     FVINITIALIZE(FVAliasBadge);
     
-    _badges = CFDictionaryCreateMutable(NULL, 0, 
&FVIntegerKeyDictionaryCallBacks, &kCFTypeDictionaryValueCallBacks);
+    _badges = [NSMutableArray new];
     NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger);
     
     NSImage *linkBadge = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kAliasBadgeIcon)];
@@ -78,7 +78,7 @@
         
         [NSGraphicsContext restoreGraphicsState];
         
-        CFDictionarySetValue(_badges, (void *)_sizes[i], layer);
+        [_badges addObject:(id)layer];
         CGLayerRelease(layer);
     }
 }
@@ -85,14 +85,14 @@
 
 + (CGLayerRef)aliasBadgeWithSize:(NSSize)size;
 {
+    NSUInteger count = [_badges count];
+    if (count == 0)
+        return NULL;
+    NSUInteger height = (NSUInteger)size.height;
     NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger);
-    for (i = 0; i < iMax; i++) {
-        
-        NSUInteger height = _sizes[i];        
-        if (height >= (NSUInteger)size.height)
-            return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)height);
-    }
-    return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)_sizes[iMax - 1]);
+    for (i = 0; i < iMax; i++)
+        if (_sizes[i] >= height) break;
+    return (CGLayerRef)[_badges objectAtIndex:MIN(i, count - 1)];
 }
 
 @end

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m     2021-01-15 
07:30:37 UTC (rev 25401)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVLockBadge.m     2021-01-15 
15:19:19 UTC (rev 25402)
@@ -41,7 +41,7 @@
 
 @implementation FVLockBadge
 
-static CFMutableDictionaryRef _badges = NULL;
+static NSMutableArray *_badges = nil;
 static const NSUInteger _sizes[] = { 32, 64, 128, 256, 512 };
 
 + (void)initialize
@@ -48,7 +48,7 @@
 {
     FVINITIALIZE(FVLockBadge);
     
-    _badges = CFDictionaryCreateMutable(NULL, 0, 
&FVIntegerKeyDictionaryCallBacks, &kCFTypeDictionaryValueCallBacks);
+    _badges = [NSMutableArray new];
     NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger);
     
     // kLockedBadgeIcon looks much better than kLockedIcon, which gets jagged 
quickly
@@ -79,7 +79,7 @@
         
         [NSGraphicsContext restoreGraphicsState];
         
-        CFDictionarySetValue(_badges, (void *)_sizes[i], layer);
+        [_badges addObject:(id)layer];
         CGLayerRelease(layer);
     }
 }
@@ -86,14 +86,14 @@
 
 + (CGLayerRef)lockBadgeWithSize:(NSSize)size;
 {
+    NSUInteger count = [_badges count];
+    if (count == 0)
+        return NULL;
+    NSUInteger height = (NSUInteger)size.height;
     NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger);
-    for (i = 0; i < iMax; i++) {
-        
-        NSUInteger height = _sizes[i];        
-        if (height >= (NSUInteger)size.height)
-            return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)height);
-    }
-    return (CGLayerRef)CFDictionaryGetValue(_badges, (void *)_sizes[iMax - 1]);
+    for (i = 0; i < iMax; i++)
+        if (_sizes[i] >= height) break;
+    return (CGLayerRef)[_badges objectAtIndex:MIN(i, count - 1)];
 }
 
 @end

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPlaceholderImage.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPlaceholderImage.m      
2021-01-15 07:30:37 UTC (rev 25401)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVPlaceholderImage.m      
2021-01-15 15:19:19 UTC (rev 25402)
@@ -40,7 +40,7 @@
 #import "FVUtilities.h"
 
 // Instruments showed a fair number of paths being created in drawing 
placeholders, and drawing an image is faster and less memory intensive than 
drawing a path each time.  Most of the path drawing overhead is in fonts, so 
there's not much we can do about that.
-static CFMutableDictionaryRef _placeholders = NULL;
+static NSMutableArray *_placeholders = nil;
 static const NSUInteger _sizes[] = { 32, 64, 128, 256, 512 };
 
 @implementation FVPlaceholderImage
@@ -49,7 +49,7 @@
 {
     FVINITIALIZE(FVPlaceholderImage);
     
-    _placeholders = CFDictionaryCreateMutable(NULL, 0, 
&FVIntegerKeyDictionaryCallBacks, &kCFTypeDictionaryValueCallBacks);
+    _placeholders = [NSMutableArray new];
     NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger);
     
     for (i = 0; i < iMax; i++) {
@@ -88,7 +88,7 @@
         
         [NSGraphicsContext restoreGraphicsState];
                 
-        CFDictionarySetValue(_placeholders, (void *)_sizes[i], layer);
+        [_placeholders addObject:(id)layer];
         CGLayerRelease(layer);
     }
 }
@@ -95,14 +95,14 @@
 
 + (CGLayerRef)placeholderWithSize:(NSSize)size;
 {
+    NSUInteger count = [_placeholders count];
+    if (count == 0)
+        return NULL;
+    NSUInteger height = (NSUInteger)size.height;
     NSUInteger i, iMax = sizeof(_sizes) / sizeof(NSUInteger);
-    for (i = 0; i < iMax; i++) {
-        
-        NSUInteger height = _sizes[i];        
-        if (height >= (NSUInteger)size.height)
-            return (CGLayerRef)CFDictionaryGetValue(_placeholders, (void 
*)height);
-    }
-    return (CGLayerRef)CFDictionaryGetValue(_placeholders, (void *)_sizes[iMax 
- 1]);
+    for (i = 0; i < iMax; i++)
+        if (_sizes[i] >= height) break;
+    return (CGLayerRef)[_placeholders objectAtIndex:MIN(i, count - 1)];
 }
 
 @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