Revision: 27777
          http://sourceforge.net/p/bibdesk/svn/27777
Author:   hofman
Date:     2022-07-29 08:58:10 +0000 (Fri, 29 Jul 2022)
Log Message:
-----------
more efficient concatenation of unique string tries

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

Modified: trunk/bibdesk/BDSKFormatParser.m
===================================================================
--- trunk/bibdesk/BDSKFormatParser.m    2022-07-28 14:55:19 UTC (rev 27776)
+++ trunk/bibdesk/BDSKFormatParser.m    2022-07-29 08:58:10 UTC (rev 27777)
@@ -840,6 +840,13 @@
        return isLocalFile ? [[papersFolderURL 
URLByAppendingPathComponent:parsedStr isDirectory:NO] path] : parsedStr;
 }
 
+static inline NSString *fullString(NSString *baseStr, NSString *endStr, char 
*chars) {
+    NSMutableString *s = [NSMutableString stringWithString:baseStr];
+    [s appendFormat:@"%s", chars];
+    [s appendString:endStr];
+    return s;
+}
+
 // returns a 'valid' string rather than a 'unique' one
 + (NSString *)uniqueString:(NSString *)baseStr
                 endingWith:(NSString *)endStr
@@ -865,7 +872,7 @@
         // consistent with the universal cite key of Papers 2 and 3
         for (n = number; n > 0; n--, hash /= charRange.length)
             fallback[n - 1] = charRange.location + (hash % charRange.length);
-        if ((uniqueStr = validator([NSString stringWithFormat:@"%@%s%@", 
baseStr, fallback, endStr])))
+        if ((uniqueStr = validator(fullString(baseStr, endStr, fallback))))
             return uniqueStr;
     } else {
         memset(fallback, NSMaxRange(charRange) - 1, number);
@@ -888,7 +895,7 @@
                 }
                 return nil;
             } else {
-                return validator([NSString stringWithFormat:@"%@%s%@", 
baseStr, chars, endStr]);
+                return validator(fullString(baseStr, endStr, chars));
             }
         };
         
@@ -898,7 +905,7 @@
     } while (number == 0);
     
     // we did not find a unique one, so just use the hash value or the final 
try
-    return [NSString stringWithFormat:@"%@%s%@", baseStr, fallback, endStr];
+    return fullString(baseStr, endStr, fallback);
 }
 
 + (BOOL)currentString:(NSString *)currentStr

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