Revision: 27670
          http://sourceforge.net/p/bibdesk/svn/27670
Author:   hofman
Date:     2022-07-01 15:06:18 +0000 (Fri, 01 Jul 2022)
Log Message:
-----------
just enumerate array, is now much faster

Modified Paths:
--------------
    trunk/bibdesk/BibDocument_UI.m

Modified: trunk/bibdesk/BibDocument_UI.m
===================================================================
--- trunk/bibdesk/BibDocument_UI.m      2022-07-01 14:57:54 UTC (rev 27669)
+++ trunk/bibdesk/BibDocument_UI.m      2022-07-01 15:06:18 UTC (rev 27670)
@@ -1395,33 +1395,6 @@
     docFlags.itemChangeMask = 0;
 }
 
-// this structure is only used in the following CFSetApplierFunction
-typedef struct __BibItemCiteKeyChangeInfo {
-    BibItem *pub;
-    NSCharacterSet *invalidSet;
-    NSString *key;
-    NSString *oldKey;
-} _BibItemCiteKeyChangeInfo;
-
-static void applyChangesToCiteFieldsWithInfo(const void *citeField, void 
*context)
-{
-    NSString *field = (NSString *)citeField;
-    _BibItemCiteKeyChangeInfo *changeInfo = context;
-    NSString *value = [changeInfo->pub valueOfField:field inherit:NO];
-    // value may be nil, so check before calling rangeOfString:
-    if (nil != value) {
-        NSRange range = [value rangeOfString:changeInfo->oldKey];
-        if (range.location != NSNotFound &&
-            (range.location == 0 || [changeInfo->invalidSet 
characterIsMember:[value characterAtIndex:range.location]]) &&
-            (NSMaxRange(range) == [value length] || [changeInfo->invalidSet 
characterIsMember:[value characterAtIndex:NSMaxRange(range)]])) {
-            NSMutableString *tmpString = [value mutableCopy];
-            [tmpString replaceCharactersInRange:range 
withString:changeInfo->key];
-            [changeInfo->pub setField:field toValue:tmpString];
-            [tmpString release];
-        }
-    }
-}
-
 - (void)handleBibItemChangedNotification:(NSNotification *)notification{
 
     // note: userInfo is nil if -[BibItem setPubFields:] is called
@@ -1464,11 +1437,6 @@
     NSCharacterSet *invalidSet = [typeManager 
invalidCharactersForField:BDSKCiteKeyString];
     NSSet *citeFields = [typeManager citationFieldsSet];
     
-    _BibItemCiteKeyChangeInfo changeInfo;
-    changeInfo.invalidSet = invalidSet;
-    changeInfo.key = key;
-    changeInfo.oldKey = oldKey;
-    
     for (BibItem *aPub in publications) {
         NSString *crossref = [aPub valueOfField:BDSKCrossrefString inherit:NO];
         if([NSString isEmptyString:crossref])
@@ -1486,10 +1454,22 @@
                 [aPub setField:BDSKCrossrefString toValue:key];
                 [changedPublications addObject:aPub];
             }
-            changeInfo.pub = aPub;
             
-            // faster than creating an enumerator for what's typically a tiny 
set (helpful when generating keys for an entire file)
-            CFSetApplyFunction((CFSetRef)citeFields, 
applyChangesToCiteFieldsWithInfo, &changeInfo);
+            for (NSString *field in citeFields) {
+                NSString *value = [aPub valueOfField:field inherit:NO];
+                // value may be nil, so check before calling rangeOfString:
+                if (nil != value) {
+                    NSRange range = [value rangeOfString:oldKey];
+                    if (range.location != NSNotFound &&
+                        (range.location == 0 || [invalidSet 
characterIsMember:[value characterAtIndex:range.location]]) &&
+                        (NSMaxRange(range) == [value length] || [invalidSet 
characterIsMember:[value characterAtIndex:NSMaxRange(range)]])) {
+                        NSMutableString *tmpString = [value mutableCopy];
+                        [tmpString replaceCharactersInRange:range 
withString:key];
+                        [aPub setField:field toValue:tmpString];
+                        [tmpString release];
+                    }
+                }
+            }
         }
     }
     

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to