Revision: 15497
          http://sourceforge.net/p/skim-app/code/15497
Author:   hofman
Date:     2025-06-18 15:55:54 +0000 (Wed, 18 Jun 2025)
Log Message:
-----------
combine conditions, create tmpdata only when needed

Modified Paths:
--------------
    trunk/SKMainDocument.m

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2025-06-18 15:48:40 UTC (rev 15496)
+++ trunk/SKMainDocument.m      2025-06-18 15:55:54 UTC (rev 15497)
@@ -899,11 +899,10 @@
     NSData *fileData = nil;
     NSData *data = nil;
     PDFDocument *pdfDoc = nil;
+    NSArray *notes = nil;
     NSError *error = nil;
     NSWorkspace *ws = [NSWorkspace sharedWorkspace];
     
-    tmpData = [[SKTemporaryData alloc] init];
-    
     if ([ws type:docType conformsToType:SKDocumentTypePDFBundle]) {
         NSURL *pdfURL = [[NSFileManager defaultManager] 
bundledFileURLWithExtension:@"pdf" inPDFBundleAtURL:absoluteURL error:&error];
         if (pdfURL) {
@@ -932,7 +931,7 @@
             BOOL foundEANotes = [array count] > 0;
             // if we found no notes, see if we had an error finding notes. If 
EAs were not supported we ignore the error, as we may assume there won't be any 
notes
             if (foundEANotes) {
-                [tmpData setNoteDicts:array];
+                notes = array;
             } else if (array == nil && isIgnorablePOSIXError(error) == NO && 
[self shouldDiscontinueAfterReadNotesError:error fromURL:absoluteURL]) {
                 fileData = nil;
                 data = nil;
@@ -947,8 +946,8 @@
                         readOption = [self definitiveOption:readOption 
usingMessageText:NSLocalizedString(@"Found Separate Notes", @"Message in alert 
dialog") informativeText:foundEANotes ? NSLocalizedString(@"A Skim notes file 
with the same name was found.  Do you want Skim to read the notes from this 
file?", @"Informative text in alert dialog") : [NSString 
stringWithFormat:NSLocalizedString(@"Unable to read notes for %@, but a Skim 
notes file with the same name was found.  Do you want Skim to read the notes 
from this file?", @"Informative text in alert dialog"), [[absoluteURL path] 
stringByAbbreviatingWithTildeInPath]]];
                         if (readOption == SKOptionAlways) {
                             array = [[NSFileManager defaultManager] 
readSkimNotesFromSkimFileAtURL:notesURL error:NULL];
-                            if ([array count] && [array 
isEqualToArray:[tmpData noteDicts]] == NO) {
-                                [tmpData setNoteDicts:array];
+                            if ([array count] && [array isEqualToArray:notes] 
== NO) {
+                                notes = array;
                                 [self 
updateChangeCount:NSChangeReadOtherContents];
                             }
                         }
@@ -958,46 +957,43 @@
         }
     }
     
-    if (data) {
-        if (pdfDoc) {
-            [self setPDFData:data];
-            [tmpData setPdfDocument:pdfDoc];
-            [self setOriginalData:fileData];
-            [fileUpdateChecker didUpdateFromURL:absoluteURL];
-            
-            NSDictionary *dictionary = nil;
-            NSArray *array = nil;
-            NSNumber *number = nil;
-            if ([docType isEqualToString:SKDocumentTypePDFBundle]) {
-                NSDictionary *info = [NSDictionary 
dictionaryWithContentsOfURL:[[absoluteURL 
URLByAppendingPathComponent:BUNDLE_DATA_FILENAME isDirectory:NO] 
URLByAppendingPathExtension:@"plist"]];
-                if ([info isKindOfClass:[NSDictionary class]]) {
-                    dictionary = [info objectForKey:SKPresentationOptionsKey];
-                    array = [info objectForKey:SKTagsKey];
-                    number = [info objectForKey:SKRatingKey];
-                }
-            } else {
-                SKNExtendedAttributeManager *eam = 
[SKNExtendedAttributeManager sharedNoSplitManager];
-                NSError *err = nil;
-                dictionary = [eam 
propertyListFromExtendedAttributeNamed:PRESENTATION_OPTIONS_KEY 
atPath:[absoluteURL path] traverseLink:YES error:&err];
-                array = [eam 
propertyListFromExtendedAttributeNamed:OPEN_META_TAGS_KEY atPath:[absoluteURL 
path] traverseLink:YES error:NULL];
-                number = [eam 
propertyListFromExtendedAttributeNamed:OPEN_META_RATING_KEY atPath:[absoluteURL 
path] traverseLink:YES error:NULL];
+    if (data && pdfDoc) {
+        tmpData = [[SKTemporaryData alloc] init];
+        [tmpData setPdfDocument:pdfDoc];
+        [tmpData setNoteDicts:notes];
+        [self setPDFData:data];
+        [self setOriginalData:fileData];
+        [fileUpdateChecker didUpdateFromURL:absoluteURL];
+        
+        NSDictionary *dictionary = nil;
+        NSArray *array = nil;
+        NSNumber *number = nil;
+        if ([docType isEqualToString:SKDocumentTypePDFBundle]) {
+            NSDictionary *info = [NSDictionary 
dictionaryWithContentsOfURL:[[absoluteURL 
URLByAppendingPathComponent:BUNDLE_DATA_FILENAME isDirectory:NO] 
URLByAppendingPathExtension:@"plist"]];
+            if ([info isKindOfClass:[NSDictionary class]]) {
+                dictionary = [info objectForKey:SKPresentationOptionsKey];
+                array = [info objectForKey:SKTagsKey];
+                number = [info objectForKey:SKRatingKey];
             }
-            if ([dictionary isKindOfClass:[NSDictionary class]] && [dictionary 
count])
-                [tmpData setPresentationOptions:dictionary];
-            if ([array isKindOfClass:[NSArray class]] && [array count])
-                [tmpData setOpenMetaTags:array];
-            if ([number respondsToSelector:@selector(doubleValue)] && [number 
doubleValue] > 0.0)
-                [tmpData setOpenMetaRating:[number doubleValue]];
+        } else {
+            SKNExtendedAttributeManager *eam = [SKNExtendedAttributeManager 
sharedNoSplitManager];
+            NSError *err = nil;
+            dictionary = [eam 
propertyListFromExtendedAttributeNamed:PRESENTATION_OPTIONS_KEY 
atPath:[absoluteURL path] traverseLink:YES error:&err];
+            array = [eam 
propertyListFromExtendedAttributeNamed:OPEN_META_TAGS_KEY atPath:[absoluteURL 
path] traverseLink:YES error:NULL];
+            number = [eam 
propertyListFromExtendedAttributeNamed:OPEN_META_RATING_KEY atPath:[absoluteURL 
path] traverseLink:YES error:NULL];
         }
-    }
-    
-    if ([tmpData pdfDocument] == nil) {
-        tmpData = nil;
+        if ([dictionary isKindOfClass:[NSDictionary class]] && [dictionary 
count])
+            [tmpData setPresentationOptions:dictionary];
+        if ([array isKindOfClass:[NSArray class]] && [array count])
+            [tmpData setOpenMetaTags:array];
+        if ([number respondsToSelector:@selector(doubleValue)] && [number 
doubleValue] > 0.0)
+            [tmpData setOpenMetaRating:[number doubleValue]];
+        
+        return YES;
+    } else {
         if (outError)
             *outError = error ?: [NSError 
readFileErrorWithLocalizedDescription:NSLocalizedString(@"Unable to load file", 
@"Error description")];
         return NO;
-    } else {
-        return YES;
     }
 }
 

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to