Reviewed by Tim Omernick
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2006 16:25:26 +0000 (16:25 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2006 16:25:26 +0000 (16:25 +0000)
        - fixed <rdar://problem/4711200> Loading history would be faster if it bypassed
        NSURL API for local files

        * History/WebHistory.m:
        (-[WebHistoryPrivate _loadHistoryGutsFromURL:savedItemsCount:collectDiscardedItemsInto:error:]):
        Load file URLs using [NSDictionary dictionaryWithContentsOfFile:]. I also cleaned up some minor
        style issues in this method, and I removed the support for old NSArray-style history files (which we
        stopped using before Safari 1.0).

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16144 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/History/WebHistory.m

index 1c598b41b54906ed5741632464780517b800582e..fe50d4c54e6e45ab7df4286eff3bd932db9d170b 100644 (file)
@@ -1,3 +1,16 @@
+2006-08-31  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Tim Omernick
+        
+        - fixed <rdar://problem/4711200> Loading history would be faster if it bypassed 
+        NSURL API for local files
+
+        * History/WebHistory.m:
+        (-[WebHistoryPrivate _loadHistoryGutsFromURL:savedItemsCount:collectDiscardedItemsInto:error:]):
+        Load file URLs using [NSDictionary dictionaryWithContentsOfFile:]. I also cleaned up some minor
+        style issues in this method, and I removed the support for old NSArray-style history files (which we
+        stopped using before Safari 1.0).
+
 2006-08-30  Adele Peterson  <adele@apple.com>
 
         Reviewed by Hyatt.
index 5dd8408cb13a4c8de414a82cb30fba5e73eee614..6ca2fbc4cd8293d6e5f0241e44b24470166e956f 100644 (file)
@@ -397,37 +397,38 @@ NSString *DatesArrayKey = @"WebHistoryDates";
 - (BOOL)_loadHistoryGutsFromURL:(NSURL *)URL savedItemsCount:(int *)numberOfItemsLoaded collectDiscardedItemsInto:(NSMutableArray *)discardedItems error:(NSError **)error
 {
     *numberOfItemsLoaded = 0;
-
-    NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:URL] returningResponse:nil error:error];
-    id propertyList = nil;
-    if (data && [data length] > 0) {
-        propertyList = [NSPropertyListSerialization propertyListFromData:data
-                                                        mutabilityOption:NSPropertyListImmutable
-                                                                  format:nil
-                                                        errorDescription:nil];
-    }
-
-    // propertyList might be an old-style NSArray or a more modern NSDictionary.
-    // If it's an NSArray, convert it to new format before further processing.
-    NSDictionary *fileAsDictionary = nil;
-    if ([propertyList isKindOfClass:[NSDictionary class]]) {
-        fileAsDictionary = propertyList;
-    } else if ([propertyList isKindOfClass:[NSArray class]]) {
-        // Convert old-style array into new-style dictionary
-        fileAsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
-            propertyList, DatesArrayKey,
-            [NSNumber numberWithInt:1], FileVersionKey,
-            nil];
+    NSDictionary *dictionary = nil;
+    
+    // Optimize loading from local file, which is faster than using the general URL loading mechanism
+    if ([URL isFileURL]) {
+        dictionary = [NSDictionary dictionaryWithContentsOfFile:[URL path]];
+        if (!dictionary) {
+#if !LOG_DISABLED
+            if ([[NSFileManager defaultManager] fileExistsAtPath:[URL path]])
+                LOG_ERROR("unable to read history from file %@; perhaps contents are corrupted", [URL path]);
+#endif
+            // else file doesn't exist, which is normal the first time
+            return NO;
+        }
     } else {
-        if ([URL isFileURL] && [[NSFileManager defaultManager] fileExistsAtPath: [URL path]]) {
-            LOG_ERROR("unable to read history from file %@; perhaps contents are corrupted", [URL path]);
+        NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:URL] returningResponse:nil error:error];
+        if (data && [data length] > 0) {
+            dictionary = [NSPropertyListSerialization propertyListFromData:data
+                mutabilityOption:NSPropertyListImmutable
+                format:nil
+                errorDescription:nil];
         }
-        return NO;
     }
+    
+
+    // We used to support NSArrays here, but that was before Safari 1.0 shipped. We will no longer support
+    // that ancient format, so anything that isn't an NSDictionary is bogus.
+    if (![dictionary isKindOfClass:[NSDictionary class]])
+        return NO;
 
-    NSNumber *fileVersionObject = [fileAsDictionary objectForKey:FileVersionKey];
+    NSNumber *fileVersionObject = [dictionary objectForKey:FileVersionKey];
     int fileVersion;
-    // we don't trust data read from disk, so double-check
+    // we don't trust data obtained from elsewhere, so double-check
     if (fileVersionObject != nil && [fileVersionObject isKindOfClass:[NSNumber class]]) {
         fileVersion = [fileVersionObject intValue];
     } else {
@@ -439,7 +440,7 @@ NSString *DatesArrayKey = @"WebHistoryDates";
         return NO;
     }    
 
-    NSArray *array = [fileAsDictionary objectForKey:DatesArrayKey];
+    NSArray *array = [dictionary objectForKey:DatesArrayKey];
         
     int itemCountLimit = [self historyItemLimit];
     NSCalendarDate *ageLimitDate = [self _ageLimitDate];