Revision: 28502
http://sourceforge.net/p/bibdesk/svn/28502
Author: hofman
Date: 2024-01-01 18:57:53 +0000 (Mon, 01 Jan 2024)
Log Message:
-----------
Use hash table for case insensitive or fussy author group sets. Don't use case
insensitive sets to compare file extensions.
Modified Paths:
--------------
trunk/bibdesk/BDSKServiceProvider.m
trunk/bibdesk/BDSKTeXTask.m
trunk/bibdesk/BibDocument.m
trunk/bibdesk/BibDocument_DataSource.m
trunk/bibdesk/BibDocument_Groups.m
trunk/bibdesk/BibItem.h
trunk/bibdesk/BibItem.m
trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h
trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m
Modified: trunk/bibdesk/BDSKServiceProvider.m
===================================================================
--- trunk/bibdesk/BDSKServiceProvider.m 2024-01-01 18:13:36 UTC (rev 28501)
+++ trunk/bibdesk/BDSKServiceProvider.m 2024-01-01 18:57:53 UTC (rev 28502)
@@ -45,7 +45,6 @@
#import "BDSKTemplate.h"
#import "BDSKTemplateObjectProxy.h"
#import "BDSKDocumentController.h"
-#import "NSSet_BDSKExtensions.h"
#import "NSURL_BDSKExtensions.h"
#import "NSPasteboard_BDSKExtensions.h"
@@ -85,8 +84,8 @@
// (we'll use a bunch of handy delimiters, including the first space, so
it's flexible.)
// alternatively we can just type the title, like we used to.
[scanner setCharactersToBeSkipped:nil];
- NSSet *citeKeyStrings = [NSSet
setForCaseInsensitiveStringsWithObjects:@"cite key", @"citekey", @"cite-key",
@"key", nil];
- NSSet *pubTypeStrings = [NSSet
setForCaseInsensitiveStringsWithObjects:@"bibtex type", @"pub type", nil];
+ NSSet *citeKeyStrings = [NSSet setWithObjects:@"cite key", @"citekey",
@"cite-key", @"key", nil];
+ NSSet *pubTypeStrings = [NSSet setWithObjects:@"bibtex type", @"pub type",
nil];
while(![scanner isAtEnd]){
// set these to nil explicitly, since we check for that later
@@ -103,9 +102,9 @@
if(queryKey && queryString){ // make sure we have both a key and a
value
// allow some additional leeway with citekey, pubtype, and All
Fields
- if([citeKeyStrings containsObject:queryKey])
+ if([citeKeyStrings containsObject:[queryKey lowercaseString]])
[searchConstraints setObject:queryString
forKey:BDSKCiteKeyString];
- else if([pubTypeStrings containsObject:queryKey])
+ else if([pubTypeStrings containsObject:[queryKey lowercaseString]])
[searchConstraints setObject:queryString
forKey:BDSKPubTypeString];
else if([BDSKAllFieldsString isCaseInsensitiveEqual:queryKey])
[searchConstraints setObject:queryString
forKey:BDSKAllFieldsString];
Modified: trunk/bibdesk/BDSKTeXTask.m
===================================================================
--- trunk/bibdesk/BDSKTeXTask.m 2024-01-01 18:13:36 UTC (rev 28501)
+++ trunk/bibdesk/BDSKTeXTask.m 2024-01-01 18:57:53 UTC (rev 28502)
@@ -41,7 +41,6 @@
#import "NSFileManager_BDSKExtensions.h"
#import "BDSKStringConstants.h"
#import "BDSKAppController.h"
-#import "NSSet_BDSKExtensions.h"
#import "NSString_BDSKExtensions.h"
#import "BDSKPreferenceController.h"
@@ -329,7 +328,7 @@
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *appSupportURL = [fm applicationSupportDirectoryURL];
NSArray *contents = [fm contentsOfDirectoryAtURL:appSupportURL
includingPropertiesForKeys:@[NSURLIsDirectoryKey]
options:NSDirectoryEnumerationSkipsHiddenFiles error:NULL];
- NSSet *helperTypes = [NSSet
setForCaseInsensitiveStringsWithObjects:@"cfg", @"sty", @"bst", nil];
+ NSSet *helperTypes = [NSSet setWithObjects:@"cfg", @"sty", @"bst", nil];
NSMutableArray *helperFileURLs = [NSMutableArray array];
// copy all user helper files from application support
@@ -336,7 +335,7 @@
for (NSURL *url in contents) {
NSNumber *isDir = nil;
[url getResourceValue:&isDir forKey:NSURLIsDirectoryKey error:NULL];
- if ([isDir boolValue] == NO && [helperTypes containsObject:[url
pathExtension]])
+ if ([isDir boolValue] == NO && [helperTypes
containsObject:[[url pathExtension]lowercaseString]])
[helperFileURLs addObject:url];
}
return helperFileURLs;
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2024-01-01 18:13:36 UTC (rev 28501)
+++ trunk/bibdesk/BibDocument.m 2024-01-01 18:57:53 UTC (rev 28502)
@@ -88,7 +88,6 @@
#import "NSArray_BDSKExtensions.h"
#import "NSTableView_BDSKExtensions.h"
#import "NSDictionary_BDSKExtensions.h"
-#import "NSSet_BDSKExtensions.h"
#import "BDSKSharingServer.h"
#import "BDSKSharingBrowser.h"
#import "BDSKTemplate.h"
@@ -2148,12 +2147,12 @@
// some common types that people might use as attachments; we don't need
to sniff these
// we /can/ create a string from these (usually), but there's no point in
wasting the memory
- NSSet *unreadableTypes = [NSSet
setForCaseInsensitiveStringsWithObjects:@"pdf", @"ps", @"eps", @"doc", @"htm",
@"textClipping", @"webloc", @"html", @"rtf", @"tiff", @"tif", @"png", @"jpg",
@"jpeg", nil];
+ NSSet *unreadableTypes = [NSSet setWithObjects:@"pdf", @"ps", @"eps",
@"doc", @"htm", @"textClipping", @"webloc", @"html", @"rtf", @"tiff", @"tif",
@"png", @"jpg", @"jpeg", nil];
NSError *parseError = nil;
NSArray *contentArray = nil;
- if ([unreadableTypes containsObject:[fileURL pathExtension]] == NO) {
+ if ([unreadableTypes containsObject:[[fileURL pathExtension]
lowercaseString]] == NO) {
// try to create a string
NSString *contentString = [[NSString alloc]
initWithContentsOfURL:fileURL guessedEncoding:[self documentStringEncoding]];
Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m 2024-01-01 18:13:36 UTC (rev
28501)
+++ trunk/bibdesk/BibDocument_DataSource.m 2024-01-01 18:57:53 UTC (rev
28502)
@@ -1327,12 +1327,12 @@
if (groupType == BDSKStaticParentGroupType) {
BibItem *pub = [pubs lastObject];
NSMutableSet *auths = [[NSMutableSet alloc] initForFuzzyAuthors];
- NSMutableSet *keywords = [[NSMutableSet alloc] initWithSet:[pub
groupsForField:BDSKKeywordsString]];
+ NSHashTable *keywords = [[pub groupsForField:BDSKKeywordsString] copy];
[auths setSet:[pub allPeople]];
for (pub in pubs) {
[auths intersectSet:[pub allPeople]];
- [keywords intersectSet:[pub groupsForField:BDSKKeywordsString]];
+ [keywords intersectHashTable:[pub
groupsForField:BDSKKeywordsString]];
}
NSString *name = NSLocalizedString(@"Group", @"Default group name");
Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m 2024-01-01 18:13:36 UTC (rev 28501)
+++ trunk/bibdesk/BibDocument_Groups.m 2024-01-01 18:57:53 UTC (rev 28502)
@@ -94,6 +94,7 @@
#import "BDSKGroupRowView.h"
#import "BDSKControlTableCellView.h"
#import "NSLayoutConstraint_BDSKExtensions.h"
+#import "NSPointerFunctions_BDSKExtensions.h"
@implementation BibDocument (Groups)
@@ -447,17 +448,6 @@
docFlags.ignoreGroupUIChange = NO;
}
-typedef struct _setAndBagContext {
- CFMutableSetRef set;
- CFMutableBagRef bag;
-} setAndBagContext;
-
-static void addObjectToSetAndBag(const void *value, void *context) {
- setAndBagContext *ctxt = context;
- CFSetAddValue(ctxt->set, value);
- CFBagAddValue(ctxt->bag, value);
-}
-
static BDSKCategoryGroup *groupWithName(NSArray *groups, id name) {
for (BDSKCategoryGroup *aGroup in groups)
if ([[aGroup name] isEqual:name])
@@ -472,13 +462,15 @@
NSString *groupField = [parent key];
BOOL isPersonField = [groupField isPersonField];
- setAndBagContext setAndBag;
+ NSHashTable *hashTable;
+ CFMutableBagRef bag;
if(isPersonField) {
- setAndBag.set = CFSetCreateMutable(kCFAllocatorDefault, 0,
&kBDSKAuthorFuzzySetCallBacks);
- setAndBag.bag = CFBagCreateMutable(kCFAllocatorDefault, 0,
&kBDSKAuthorFuzzyBagCallBacks);
+ hashTable = [[NSHashTable alloc]
initWithPointerFunctions:[NSPointerFunctions fuzzyAuthorPointerFunctions]
capacity:0];
+ CFSetCreateMutable(kCFAllocatorDefault, 0,
&kBDSKAuthorFuzzySetCallBacks);
+ bag = CFBagCreateMutable(kCFAllocatorDefault, 0,
&kBDSKAuthorFuzzyBagCallBacks);
} else {
- setAndBag.set = CFSetCreateMutable(kCFAllocatorDefault, 0,
&kBDSKCaseInsensitiveStringSetCallBacks);
- setAndBag.bag = CFBagCreateMutable(kCFAllocatorDefault, 0,
&kBDSKCaseInsensitiveStringBagCallBacks);
+ hashTable = [[NSHashTable alloc]
initWithPointerFunctions:[NSPointerFunctions
caseInsensitiveStringPointerFunctions] capacity:0];
+ bag = CFBagCreateMutable(kCFAllocatorDefault, 0,
&kBDSKCaseInsensitiveStringBagCallBacks);
}
NSArray *oldGroups = [parent categoryGroups];
@@ -489,20 +481,24 @@
NSInteger emptyCount = 0;
- NSSet *tmpSet = nil;
+ NSHashTable *tmpSet = nil;
for (BibItem *pub in publications) {
tmpSet = [pub groupsForField:groupField];
- if([tmpSet count])
- CFSetApplyFunction((CFSetRef)tmpSet, addObjectToSetAndBag,
&setAndBag);
- else
+ if([tmpSet count]) {
+ for (id object in tmpSet) {
+ [hashTable addObject:object];
+ CFBagAddValue(bag, object);
+ }
+ } else {
emptyCount++;
+ }
}
- NSMutableArray *mutableGroups = [[NSMutableArray alloc]
initWithCapacity:CFSetGetCount(setAndBag.set) + 1];
+ NSMutableArray *mutableGroups = [[NSMutableArray alloc]
initWithCapacity:[hashTable count] + 1];
// now add the group names that we found from our BibItems, using a
generic folder icon
- for (id groupName in (NSSet *)(setAndBag.set)) {
+ for (id groupName in hashTable) {
group = groupWithName(oldGroups, groupName);
// don't reuse groups with invalidated authors
if (isPersonField && [(BibAuthor *)[group name] publication] == nil)
@@ -511,7 +507,7 @@
[group retain];
else
group = [[BDSKCategoryGroup alloc] initWithName:groupName
key:groupField];
- [group setCount:CFBagGetCountOfValue(setAndBag.bag, groupName)];
+ [group setCount:CFBagGetCountOfValue(bag, groupName)];
[mutableGroups addObject:group];
[group release];
}
@@ -529,8 +525,8 @@
}
[parent setCategoryGroups:mutableGroups];
- CFRelease(setAndBag.set);
- CFRelease(setAndBag.bag);
+ [hashTable release];
+ CFRelease(bag);
[mutableGroups release];
}
Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h 2024-01-01 18:13:36 UTC (rev 28501)
+++ trunk/bibdesk/BibItem.h 2024-01-01 18:57:53 UTC (rev 28502)
@@ -780,7 +780,7 @@
- (BOOL)duplicateTitleToBooktitleOverwriting:(BOOL)overwrite;
- (NSArray *)groupArrayForField:(NSString *)field;
-- (NSSet *)groupsForField:(NSString *)field;
+- (NSHashTable *)groupsForField:(NSString *)field;
- (BDSKFieldAction)addToGroup:(BDSKCategoryGroup *)group
handleInherited:(BDSKFieldAction)operation;
- (BDSKFieldAction)removeFromGroup:(BDSKCategoryGroup *)group
handleInherited:(BDSKFieldAction)operation;
- (BDSKFieldAction)replaceGroup:(BDSKCategoryGroup *)group
withGroup:(BDSKCategoryGroup *)newGroup
handleInherited:(BDSKFieldAction)operation;
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2024-01-01 18:13:36 UTC (rev 28501)
+++ trunk/bibdesk/BibItem.m 2024-01-01 18:57:53 UTC (rev 28502)
@@ -78,6 +78,7 @@
#import "BDSKEntrezGroupServer.h"
#import "BDSKDOIParser.h"
#import "BDSKItemDownload.h"
+#import "NSPointerFunctions_BDSKExtensions.h"
NSString *BDSKBibItemKeyKey = @"key";
NSString *BDSKBibItemOldValueKey = @"oldValue";
@@ -3470,28 +3471,30 @@
}
}
-- (NSSet *)groupsForField:(NSString *)field{
+- (NSHashTable *)groupsForField:(NSString *)field{
if ([field isEqualToString:BDSKColorLabelString])
field = BDSKColorString;
// first see if we had it cached
- NSSet *groupSet = [groups objectForKey:field];
+ NSHashTable *groupSet = [groups objectForKey:field];
if(groupSet)
return groupSet;
// otherwise build it if we have a value
- NSMutableSet *mutableGroupSet;
+ NSHashTable *hashTable;
if([field isPersonField]){
- mutableGroupSet = [[NSMutableSet alloc] initForFuzzyAuthors];
- [mutableGroupSet addObjectsFromArray:[self peopleArrayForField:field]];
+ hashTable = [[NSHashTable alloc]
initWithPointerFunctions:[NSPointerFunctions fuzzyAuthorPointerFunctions]
capacity:0];
+ for (BibAuthor *object in [self peopleArrayForField:field])
+ [hashTable addObject:object];
}else{
- mutableGroupSet = [NSMutableSet newForCaseInsensitiveStrings];
- [mutableGroupSet addObjectsFromArray:[self groupArrayForField:field]];
+ hashTable = [[NSHashTable alloc]
initWithPointerFunctions:[NSPointerFunctions
caseInsensitiveStringPointerFunctions] capacity:0];
+ for (NSString *object in [self groupArrayForField:field])
+ [hashTable addObject:object];
}
- [groups setObject:mutableGroupSet forKey:field];
- [mutableGroupSet release];
+ [groups setObject:hashTable forKey:field];
+ [hashTable release];
return [groups objectForKey:field];
}
Modified: trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h 2024-01-01 18:13:36 UTC
(rev 28501)
+++ trunk/bibdesk/NSPointerFunctions_BDSKExtensions.h 2024-01-01 18:57:53 UTC
(rev 28502)
@@ -42,5 +42,6 @@
@interface NSPointerFunctions (BDSKExtensions)
+ (NSPointerFunctions *)caseInsensitiveStringPointerFunctions;
++ (NSPointerFunctions *)fuzzyAuthorPointerFunctions;
@end
Modified: trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m 2024-01-01 18:13:36 UTC
(rev 28501)
+++ trunk/bibdesk/NSPointerFunctions_BDSKExtensions.m 2024-01-01 18:57:53 UTC
(rev 28502)
@@ -37,6 +37,7 @@
*/
#import "NSPointerFunctions_BDSKExtensions.h"
+#import "BibAuthor.h"
static BOOL caseInsensitiveStringEqual(const void *item1, const void *item2,
NSUInteger (*size)(const void *item)) {
return CFStringCompare(item1, item2, kCFCompareCaseInsensitive |
kCFCompareNonliteral) == kCFCompareEqualTo;
@@ -68,6 +69,18 @@
return hash;
}
+static NSUInteger BibAuthorFuzzyHash(const void *item, NSUInteger
(*size)(const void *item))
+{
+ BDSKASSERT([(id)item isKindOfClass:[BibAuthor class]]);
+ return [(BibAuthor *)item fuzzyHash];
+}
+
+static BOOL BibAuthorFuzzyEqual(const void *value1, const void *value2,
NSUInteger (*size)(const void *item))
+{
+ BDSKASSERT([(id)value1 isKindOfClass:[BibAuthor class]] && [(id)value2
isKindOfClass:[BibAuthor class]]);
+ return [(BibAuthor *)value1 fuzzyEqual:(BibAuthor *)value2];
+}
+
@implementation NSPointerFunctions (BDSKExtensions)
+ (NSPointerFunctions *)caseInsensitiveStringPointerFunctions {
@@ -77,4 +90,11 @@
return pointerFunctions;
}
++ (NSPointerFunctions *)fuzzyAuthorPointerFunctions {
+ NSPointerFunctions *pointerFunctions = [self
pointerFunctionsWithOptions:NSPointerFunctionsWeakMemory |
NSPointerFunctionsObjectPersonality];;
+ [pointerFunctions setIsEqualFunction:&BibAuthorFuzzyEqual];
+ [pointerFunctions setHashFunction:&BibAuthorFuzzyHash];
+ 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