Revision: 28546
http://sourceforge.net/p/bibdesk/svn/28546
Author: hofman
Date: 2024-01-05 00:09:34 +0000 (Fri, 05 Jan 2024)
Log Message:
-----------
use objc methods to create and release NSMapTables
Modified Paths:
--------------
trunk/bibdesk/BDSKGroupOutlineView.m
trunk/bibdesk/BDSKLineNumberView.m
trunk/bibdesk/BDSKLineTextField.m
trunk/bibdesk/BibDocument_Menus.m
trunk/bibdesk/BibItem.m
trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h
trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m
Modified: trunk/bibdesk/BDSKGroupOutlineView.m
===================================================================
--- trunk/bibdesk/BDSKGroupOutlineView.m 2024-01-04 23:39:41 UTC (rev
28545)
+++ trunk/bibdesk/BDSKGroupOutlineView.m 2024-01-05 00:09:34 UTC (rev
28546)
@@ -84,7 +84,7 @@
CGFloat size = [newFont pointSize];
if ([self font] == nil || fabs([[self font] pointSize] - size) > 0.0) {
[countString addAttribute:NSFontAttributeName value:[NSFont
fontWithName:@"Helvetica-Bold" size:size] ?: [NSFont boldSystemFontOfSize:size]
range:NSMakeRange(0, [countString length])];
- if (countImages) NSResetMapTable(countImages);
+ if (countImages) [countImages removeAllObjects];
}
[super setFont:newFont];
[self setAlternateRowHeight:[self rowHeight] + [[newFont smallerFont]
defaultViewLineHeight]];
@@ -124,7 +124,7 @@
}
- (NSImage *)makeBubbleImageWithCount:(NSInteger)count {
- NSImage *countImage = countImages ? NSMapGet(countImages, (const void
*)count) : nil;
+ NSImage *countImage = countImages ? (__bridge NSImage
*)NSMapGet(countImages, (const void *)count) : nil;
if (countImage == nil) {
[countString replaceCharactersInRange:NSMakeRange(0, [countString
length]) withString:[NSString stringWithFormat:@"%ld", (long)count]];
NSSize size = [countString
boundingRectWithSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX) options:0].size;
@@ -170,8 +170,8 @@
}
[countImage setTemplate:YES];
if (countImages == nil)
- countImages = NSCreateMapTable(NSIntegerMapKeyCallBacks,
NSObjectMapValueCallBacks, 0);
- NSMapInsert(countImages, (const void *)count, countImage);
+ countImages = [[NSMapTable alloc]
initWithKeyOptions:NSPointerFunctionsOpaqueMemory |
NSPointerFunctionsIntegerPersonality
valueOptions:NSPointerFunctionsStrongMemory |
NSPointerFunctionsObjectPersonality capacity:0];
+ NSMapInsert(countImages, (__bridge const void *)count, countImage);
}
return countImage;
}
Modified: trunk/bibdesk/BDSKLineNumberView.m
===================================================================
--- trunk/bibdesk/BDSKLineNumberView.m 2024-01-04 23:39:41 UTC (rev 28545)
+++ trunk/bibdesk/BDSKLineNumberView.m 2024-01-05 00:09:34 UTC (rev 28546)
@@ -63,8 +63,7 @@
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
BDSKDESTROY(lineCharacterIndexes);
- if (errorMarkers) NSFreeMapTable(errorMarkers);
- errorMarkers = nil;
+ BDSKDESTROY(errorMarkers);
[super dealloc];
}
@@ -98,15 +97,15 @@
- (void)setMarkers:(NSArray *)markers {
[super setMarkers:markers];
if (errorMarkers)
- NSResetMapTable(errorMarkers);
+ [errorMarkers removeAllObjects];
else
- errorMarkers = NSCreateMapTable(NSIntegerMapKeyCallBacks,
NSObjectMapValueCallBacks, 0);
+ errorMarkers = [[NSMapTable alloc]
initWithKeyOptions:NSPointerFunctionsOpaqueMemory |
NSPointerFunctionsIntegerPersonality
valueOptions:NSPointerFunctionsStrongMemory |
NSPointerFunctionsObjectPersonality capacity:0];
for (NSRulerMarker *marker in markers) {
id object = [marker representedObject];
if ([object isKindOfClass:[BDSKErrorObject class]]) {
NSInteger line = [object lineNumber];
if (line > 0)
- NSMapInsert(errorMarkers, (const void *)(line - 1), marker);
+ NSMapInsert(errorMarkers, (const void *)(line - 1), (__bridge
void *)marker);
}
}
}
@@ -118,8 +117,8 @@
NSInteger line = [object lineNumber];
if (line > 0) {
if (errorMarkers == nil)
- errorMarkers = NSCreateMapTable(NSIntegerMapKeyCallBacks,
NSObjectMapValueCallBacks, 0);
- NSMapInsert(errorMarkers, (const void *)(line - 1), marker);
+ errorMarkers = [[NSMapTable alloc]
initWithKeyOptions:NSPointerFunctionsOpaqueMemory |
NSPointerFunctionsIntegerPersonality
valueOptions:NSPointerFunctionsStrongMemory |
NSPointerFunctionsObjectPersonality capacity:0];
+ NSMapInsert(errorMarkers, (const void *)(line - 1), (__bridge
id)marker);
}
}
}
@@ -223,7 +222,7 @@
if (NSLocationInRange(i, range)) {
rects = [lm rectArrayForCharacterRange:NSMakeRange(i, 0)
withinSelectedCharacterRange:nullRange inTextContainer:container
rectCount:&rectCount];
if (rectCount > 0) {
- if (errorMarkers && (marker = NSMapGet(errorMarkers,
(const void *)line))) {
+ if (errorMarkers && (marker = (__bridge
id)NSMapGet(errorMarkers, (const void *)line))) {
markerRect.origin.y = offsetY + NSMidY(rects[0]) - 0.5
* MARKER_THICKNESS;
[[marker image] drawFlipped:[self isFlipped]
inRect:markerRect fromRect:NSZeroRect
operation:NSCompositingOperationSourceOver fraction:1.0];
[self addToolTipRect:markerRect owner:self
userData:(void *)line];
@@ -245,7 +244,7 @@
- (void)mouseDown:(NSEvent *)theEvent {}
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag
point:(NSPoint)point userData:(void *)userData {
- NSRulerMarker *marker = NSMapGet(errorMarkers, userData);
+ NSRulerMarker *marker = (__bridge id)NSMapGet(errorMarkers, userData);
BDSKErrorObject *error = (BDSKErrorObject *)[marker representedObject];
return [NSString stringWithFormat:@"%@: %@", [error errorClassName],
[error errorMessage]];
}
Modified: trunk/bibdesk/BDSKLineTextField.m
===================================================================
--- trunk/bibdesk/BDSKLineTextField.m 2024-01-04 23:39:41 UTC (rev 28545)
+++ trunk/bibdesk/BDSKLineTextField.m 2024-01-05 00:09:34 UTC (rev 28546)
@@ -38,6 +38,7 @@
#import "BDSKLineTextField.h"
#import "NSFont_BDSKExtensions.h"
+#import "NSPointerFunctions_BDSKExtensions.h"
@implementation BDSKLineTextField
@@ -45,13 +46,12 @@
- (NSSize)intrinsicContentSize {
static NSMapTable *heightTable = nil;
NSFont *font = [self font];
- CGFloat *height = heightTable ? NSMapGet(heightTable, font) : NULL;
+ CGFloat *height = heightTable ? (CGFloat *)NSMapGet(heightTable, (__bridge
void *)font) : NULL;
if (height == NULL) {
- height = malloc(sizeof(CGFloat));
*height = [[self font] defaultViewLineHeight];
if (heightTable == nil)
- heightTable = NSCreateMapTable(NSObjectMapKeyCallBacks,
NSOwnedPointerMapValueCallBacks, 0);
- NSMapInsert(heightTable, font, height);
+ heightTable = [[NSMapTable alloc]
initWithKeyPointerFunctions:[NSPointerFunctions
pointerFunctionsWithOptions:NSPointerFunctionsStrongMemory |
NSPointerFunctionsObjectPersonality] valuePointerFunctions:[NSPointerFunctions
floatPointerFunctions] capacity:0];
+ NSMapInsert(heightTable, (__bridge void *)font, (void *)height);
}
return NSMakeSize(NSViewNoIntrinsicMetric, *height);
}
Modified: trunk/bibdesk/BibDocument_Menus.m
===================================================================
--- trunk/bibdesk/BibDocument_Menus.m 2024-01-04 23:39:41 UTC (rev 28545)
+++ trunk/bibdesk/BibDocument_Menus.m 2024-01-05 00:09:34 UTC (rev 28546)
@@ -583,7 +583,7 @@
return NULL;
// selectors are unique global "constants" so don't need to be retained
and can be compared using pointer equivalence
if (table == NULL)
- table = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0);
+ table = [[NSMapTable alloc]
initWithKeyOptions:NSPointerFunctionsOpaqueMemory |
NSPointerFunctionsOpaquePersonality valueOptions:NSPointerFunctionsOpaqueMemory
| NSPointerFunctionsOpaquePersonality capacity:0];
SEL validateSel = NSMapGet(table, sel);
if (validateSel == NULL) {
const char *name = sel_getName(sel);
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2024-01-04 23:39:41 UTC (rev 28545)
+++ trunk/bibdesk/BibItem.m 2024-01-05 00:09:34 UTC (rev 28546)
@@ -146,16 +146,16 @@
placeholderCiteKey = @"FixMe";
// Create a table of field/SEL pairs used for searching
- NSMapTable *mapTable = NSCreateMapTable(NSObjectMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0);
+ NSMapTable *mapTable = [[NSMapTable alloc]
initWithKeyOptions:NSPointerFunctionsStrongMemory |
NSPointerFunctionsObjectPersonality valueOptions:NSPointerFunctionsOpaqueMemory
| NSPointerFunctionsOpaquePersonality capacity:0];
- NSMapInsert(mapTable, BDSKTitleString, @selector(title));
- NSMapInsert(mapTable, BDSKAuthorString, @selector(bibTeXAuthorString));
- NSMapInsert(mapTable, BDSKAllFieldsString, @selector(allFieldsString));
- NSMapInsert(mapTable, BDSKPubTypeString, @selector(pubType));
- NSMapInsert(mapTable, BDSKCiteKeyString, @selector(citeKey));
+ NSMapInsert(mapTable, (__bridge void *)BDSKTitleString, @selector(title));
+ NSMapInsert(mapTable, (__bridge void *)BDSKAuthorString,
@selector(bibTeXAuthorString));
+ NSMapInsert(mapTable, (__bridge void *)BDSKAllFieldsString,
@selector(allFieldsString));
+ NSMapInsert(mapTable, (__bridge void *)BDSKPubTypeString,
@selector(pubType));
+ NSMapInsert(mapTable, (__bridge void *)BDSKCiteKeyString,
@selector(citeKey));
- selectorTable = NSCopyMapTableWithZone(mapTable, NULL);
- NSFreeMapTable(mapTable);
+ selectorTable = [mapTable copy];
+ [mapTable release];
// hidden pref as support for RFE #1690155
https://sourceforge.net/tracker/index.php?func=detail&aid=1690155&group_id=61487&atid=497426
// partially implemented; view will represent this as inherited unless it
goes through -[BibItem valueOfField:inherit:], which fields like "Key"
certainly will
@@ -1580,7 +1580,7 @@
- (BOOL)matchesSubstring:(NSString *)substring inField:(NSString *)field;
{
- SEL selector = (SEL)NSMapGet(selectorTable, field);
+ SEL selector = (SEL)NSMapGet(selectorTable, (__bridge void *)field);
if (NULL == selector) {
if ([field isBooleanField])
return [self boolValueOfField:field] == [substring booleanValue];
Modified: trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h 2024-01-04 23:39:41 UTC
(rev 28545)
+++ trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h 2024-01-05 00:09:34 UTC
(rev 28546)
@@ -45,5 +45,6 @@
+ (NSPointerFunctions *)fuzzyAuthorPointerFunctions;
+ (NSPointerFunctions *)itemEqualityPointerFunctions;
+ (NSPointerFunctions *)itemEquivalencePointerFunctions;
++ (NSPointerFunctions *)floatPointerFunctions;
@end
Modified: trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m 2024-01-04 23:39:41 UTC
(rev 28545)
+++ trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m 2024-01-05 00:09:34 UTC
(rev 28546)
@@ -89,6 +89,10 @@
return [(__bridge BibItem *)item equivalenceHash];
}
+static NSUInteger floatSizeFunction(const void *item) { return
sizeof(NSPoint); }
+
+static NSString *floatDescriptionFunction(const void *item) { return [NSString
stringWithFormat:@"%f", *(CGFloat *)item]; }
+
@implementation NSPointerFunctions (BDSKExtensions)
+ (NSPointerFunctions *)caseInsensitiveStringPointerFunctions {
@@ -119,4 +123,11 @@
return pointerFunctions;
}
++ (NSPointerFunctions *)floatPointerFunctions {
+ NSPointerFunctions *pointerFunctions = [self
pointerFunctionsWithOptions:NSPointerFunctionsMallocMemory |
NSPointerFunctionsCopyIn | NSPointerFunctionsStructPersonality];
+ [pointerFunctions setSizeFunction:floatSizeFunction];
+ [pointerFunctions setDescriptionFunction:floatDescriptionFunction];
+ return pointerFunctions;
+}
+
@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