diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-19 04:40:25 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-19 04:40:25 -0800 |
commit | 34f70f5d76b33cddc31cba1d22ff510535f1e4d5 (patch) | |
tree | 4630176e28cdcece07df8cc45d7e45ba233d7996 | |
parent | b13b8664e70405f065a37d67fb4eb7c39a6a438b (diff) |
Drastic simplification of Source management.
-rw-r--r-- | MobileCydia.mm | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index b14cda1..361f919 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -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 { |