From 34f70f5d76b33cddc31cba1d22ff510535f1e4d5 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 19 Feb 2011 04:40:25 -0800 Subject: [PATCH] Drastic simplification of Source management. --- MobileCydia.mm | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/MobileCydia.mm b/MobileCydia.mm index b14cda12..361f9196 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1301,8 +1301,9 @@ typedef std::map< unsigned long, _H > SourceMap; SPtr manager_; pkgSourceList *list_; - SourceMap sources_; - CFMutableArrayRef deadSources_; + SourceMap sourceMap_; + NSMutableArray *sourceList_; + CFMutableArrayRef packages_; _transient NSObject *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 *indices = (*source)->GetIndexFiles(); for (std::vector::const_iterator index = indices->begin(); index != indices->end(); ++index) // XXX: this could be more intelligent if (dynamic_cast(*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 { -- 2.45.2