]> git.saurik.com Git - cydia.git/commitdiff
Drastic simplification of Source management.
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 19 Feb 2011 12:40:25 +0000 (04:40 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 19 Feb 2011 12:40:25 +0000 (04:40 -0800)
MobileCydia.mm

index b14cda12640c0573612b67af4bf900305514dc77..361f9196aeef5d5edf93d1c47bdf96d8cb299352 100644 (file)
@@ -1301,8 +1301,9 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
     SPtr<pkgPackageManager> manager_;
     pkgSourceList *list_;
 
-    SourceMap sources_;
-    CFMutableArrayRef deadSources_;
+    SourceMap sourceMap_;
+    NSMutableArray *sourceList_;
+
     CFMutableArrayRef packages_;
 
     _transient NSObject<ConfigurationDelegate, ProgressDelegate> *delegate_;
@@ -3202,8 +3203,7 @@ static NSString *Warning_;
 - (void) dealloc {
     // XXX: actually implement this thing
     _assert(false);
-    if (deadSources_)
-        CFRelease(deadSources_);
+    [sourceList_ release];
     [self releasePackages];
     apr_pool_destroy(pool_);
     NSRecycleZone(zone_);
@@ -3321,7 +3321,7 @@ static NSString *Warning_;
             capacity += 1024;
 
         packages_ = CFArrayCreateMutable(kCFAllocatorDefault, capacity, NULL);
-        deadSources_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
+        sourceList_ = [[NSMutableArray alloc] initWithCapacity:16];
 
         int fds[2];
 
@@ -3393,11 +3393,7 @@ static NSString *Warning_;
 }
 
 - (NSArray *) sources {
-    NSMutableArray *sources([NSMutableArray arrayWithCapacity:sources_.size()]);
-    for (SourceMap::const_iterator i(sources_.begin()); i != sources_.end(); ++i)
-        [sources addObject:i->second];
-    [sources addObjectsFromArray:(NSArray *)deadSources_];
-    return sources;
+    return sourceList_;
 }
 
 - (Source *) sourceWithKey:(NSString *)key {
@@ -3445,8 +3441,8 @@ static NSString *Warning_;
 
     [self releasePackages];
 
-    sources_.clear();
-    CFArrayRemoveAllValues(deadSources_);
+    sourceMap_.clear();
+    [sourceList_ removeAllObjects];
 
     _error->Discard();
 
@@ -3541,19 +3537,17 @@ static NSString *Warning_;
     }
 
     for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
-        bool found = false;
+        Source *object([[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease]);
+        [sourceList_ addObject:object];
+
         std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
         for (std::vector<pkgIndexFile *>::const_iterator index = indices->begin(); index != indices->end(); ++index)
             // XXX: this could be more intelligent
             if (dynamic_cast<debPackagesIndex *>(*index) != NULL) {
                 pkgCache::PkgFileIterator cached((*index)->FindInCache(cache_));
-                if (!cached.end()) {
-                    sources_[cached->ID] = [[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease];
-                    found = true;
-                }
+                if (!cached.end())
+                    sourceMap_[cached->ID] = object;
             }
-        if (!found)
-            CFArrayAppendValue(deadSources_, [[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease]);
     }
 
     {
@@ -3798,8 +3792,8 @@ static NSString *Warning_;
 }
 
 - (Source *) getSource:(pkgCache::PkgFileIterator)file {
-    SourceMap::const_iterator i(sources_.find(file->ID));
-    return i == sources_.end() ? nil : i->second;
+    SourceMap::const_iterator i(sourceMap_.find(file->ID));
+    return i == sourceMap_.end() ? nil : i->second;
 }
 
 - (NSString *) mappedSectionForPointer:(const char *)section {