Skip to content

Commit

Permalink
use NSFastEnumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
ssp committed Apr 27, 2011
1 parent 674816a commit b669e7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
34 changes: 14 additions & 20 deletions delimport/DIBookmarksController.m
Expand Up @@ -164,19 +164,17 @@ - (void) verifyMetadataCache {
NSFileManager * fM = [[NSFileManager alloc] init];
NSMutableArray * bookmarksNeedingUpdate = [NSMutableArray array];

for (NSDictionary * bookmark in bookmarks) {
NSString * hash = [bookmark objectForKey: DIHashKey];
if (hash != nil) {
// bookmark files
NSDictionary * fileBookmark = [fileController readDictionaryForHash:hash];
if (fileBookmark == nil || [bookmark isEqualToDictionary:fileBookmark] == NO) {
// we don't have a bookmkark or the bookmark ist not in sync with the cache
// NSLog(@"replacing cache file %@", hash);
[bookmarksNeedingUpdate addObject:bookmark];
}
else if (![fM fileExistsAtPath:[DIFileController webarchivePathForHash:hash]]) {
[fileController fetchWebarchiveForDictionary:bookmark];
}
for (NSString * hash in bookmarks) {
NSDictionary * bookmark = [bookmarks objectForKey:hash];
// bookmark files
NSDictionary * fileBookmark = [fileController readDictionaryForHash:hash];
if (fileBookmark == nil || [bookmark isEqualToDictionary:fileBookmark] == NO) {
// we don't have a bookmark or the bookmark ist not in sync with the cache
// NSLog(@"replacing cache file %@", hash);
[bookmarksNeedingUpdate addObject:bookmark];
}
else if (![fM fileExistsAtPath:[DIFileController webarchivePathForHash:hash]]) {
[fileController fetchWebarchiveForDictionary:bookmark];
}
}

Expand Down Expand Up @@ -277,15 +275,11 @@ - (void) updateList: (NSTimer *) timer {
// avoid reading those as they'll destroy our metadata cache
NSMutableDictionary *updatedPosts = [NSMutableDictionary dictionary];

NSEnumerator *postEnumerator = [[root children] objectEnumerator];
NSXMLElement *post;
while ((post = [postEnumerator nextObject])) {
for (NSXMLElement * post in [root children]) {
NSMutableDictionary * postDictionary = [NSMutableDictionary dictionary];

NSString * hash = nil;
NSEnumerator * attributeEnumerator = [[post attributes] objectEnumerator];
NSXMLNode * attribute;
while ((attribute = [attributeEnumerator nextObject])) {

for (NSXMLNode * attribute in [post attributes]) {
if ([[attribute name] isEqualToString: DITimeKey]) {
[postDictionary setObject:[self dateFromXMLDateString:[attribute stringValue]] forKey:[attribute name]];
} else if ([[attribute name] isEqualToString: DITagKey]) {
Expand Down
8 changes: 2 additions & 6 deletions delimport/DIFileController.m
Expand Up @@ -175,9 +175,7 @@ - (void) deleteDictionary: (NSDictionary *) dictionary {


- (void) saveDictionaries: (NSArray *) dictionaries {
NSEnumerator *dictEnumerator = [dictionaries objectEnumerator];
NSDictionary *dictionary;
while ((dictionary = [dictEnumerator nextObject])) {
for (NSDictionary * dictionary in dictionaries) {
[self saveDictionary: dictionary];
[self fetchWebarchiveForDictionary: dictionary];
}
Expand All @@ -186,9 +184,7 @@ - (void) saveDictionaries: (NSArray *) dictionaries {


- (void) deleteDictionaries: (NSArray *) dictionaries {
NSEnumerator *dictEnumerator = [dictionaries objectEnumerator];
NSDictionary *dictionary;
while ((dictionary = [dictEnumerator nextObject])) {
for (NSDictionary * dictionary in dictionaries) {
[self deleteDictionary:dictionary];
// for the moment don’t delete web archives
}
Expand Down

0 comments on commit b669e7d

Please sign in to comment.