X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/220fa2b077e4e55b36697b39a7a1cf3f380faa38..10ec8df9b1abae24b27e1167ae0a02adac66c5aa:/Cydia.mm diff --git a/Cydia.mm b/Cydia.mm index ff3d34c5..c40a0d27 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -226,12 +226,18 @@ class _H { Clear_(); } + _finline operator Type_ *() const { + return value_; + } + _finline This_ &operator =(Type_ *value) { if (value_ != value) { - Clear_(); + Type_ *old(value_); value_ = value; Retain_(); - } return this; + if (old != nil) + [old release]; + } return *this; } }; /* }}} */ @@ -399,7 +405,7 @@ extern NSString * const kCAFilterNearest; #define ForRelease 0 #define TraceLogging (1 && !ForRelease) #define HistogramInsertionSort (0 && !ForRelease) -#define ProfileTimes (0 && !ForRelease) +#define ProfileTimes (1 && !ForRelease) #define ForSaurik (0 && !ForRelease) #define LogBrowser (0 && !ForRelease) #define TrackResize (0 && !ForRelease) @@ -1132,18 +1138,15 @@ NSString *SizeString(double size) { return [NSString stringWithFormat:@"%s%.1f %s", (negative ? "-" : ""), size, powers_[power]]; } -NSString *StripVersion(const char *version) { +static _finline CFStringRef CFCString(const char *value) { + return CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(value), strlen(value), kCFStringEncodingUTF8, NO, kCFAllocatorNull); +} + +CFStringRef StripVersion(const char *version) { const char *colon(strchr(version, ':')); if (colon != NULL) version = colon + 1; - return [NSString stringWithUTF8String:version]; -} - -NSString *StripVersion(NSString *version) { - NSRange colon = [version rangeOfString:@":"]; - if (colon.location != NSNotFound) - version = [version substringFromIndex:(colon.location + 1)]; - return version; + return CFCString(version); } NSString *LocalizeSection(NSString *section) { @@ -1347,6 +1350,8 @@ class Progress : /* }}} */ /* Database Interface {{{ */ +typedef std::map< unsigned long, _H > SourceMap; + @interface Database : NSObject { NSZone *zone_; apr_pool_t *pool_; @@ -1362,7 +1367,7 @@ class Progress : SPtr manager_; pkgSourceList *list_; - NSMutableDictionary *sources_; + SourceMap sources_; NSMutableArray *packages_; _transient NSObject *delegate_; @@ -1657,6 +1662,7 @@ class Progress : /* Package Class {{{ */ @interface Package : NSObject { unsigned era_; + apr_pool_t *pool_; pkgCache::VerIterator version_; pkgCache::PkgIterator iterator_; @@ -1665,6 +1671,7 @@ class Progress : Source *source_; bool cached_; + bool parsed_; CYString section_; NSString *section$_; @@ -1688,7 +1695,7 @@ class Progress : Address *author$_; CYString support_; - NSArray *tags_; + NSMutableArray *tags_; NSString *role_; NSArray *relationships_; @@ -1703,6 +1710,7 @@ class Progress : + (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database; - (pkgCache::PkgIterator) iterator; +- (void) parse; - (NSString *) section; - (NSString *) simpleSection; @@ -1959,100 +1967,124 @@ struct PackageNameOrdering : return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name]; } +- (void) parse { + if (parsed_) + return; + parsed_ = true; + if (file_.end()) + return; + + _profile(Package$parse) + pkgRecords::Parser *parser; + + _profile(Package$parse$Lookup) + parser = &[database_ records]->Lookup(file_); + _end + + CYString website; + + _profile(Package$parse$Find) + struct { + const char *name_; + CYString *value_; + } names[] = { + {"icon", &icon_}, + {"depiction", &depiction_}, + {"homepage", &homepage_}, + {"website", &website}, + {"support", &support_}, + {"sponsor", &sponsor_}, + {"author", &author_}, + }; + + for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) { + const char *start, *end; + + if (parser->Find(names[i].name_, start, end)) { + CYString &value(*names[i].value_); + _profile(Package$parse$Value) + value.set(pool_, start, end - start); + _end + } + } + _end + + _profile(Package$parse$Tagline) + const char *start, *end; + if (parser->ShortDesc(start, end)) { + const char *stop(reinterpret_cast(memchr(start, '\n', end - start))); + if (stop == NULL) + stop = end; + while (stop != start && stop[-1] == '\r') + --stop; + tagline_.set(pool_, start, stop - start); + } + _end + + _profile(Package$parse$Retain) + if (!homepage_.empty()) + homepage_ = website; + if (homepage_ == depiction_) + homepage_.clear(); + _end + _end +} + - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database { if ((self = [super init]) != nil) { _profile(Package$initWithVersion) @synchronized (database) { era_ = [database era]; + pool_ = pool; version_ = version; iterator_ = version.ParentPkg(); database_ = database; _profile(Package$initWithVersion$Latest) - latest_ = [StripVersion(version_.VerStr()) retain]; + latest_ = (NSString *) StripVersion(version_.VerStr()); _end - pkgCache::VerIterator current(iterator_.CurrentVer()); - if (!current.end()) - installed_ = [StripVersion(current.VerStr()) retain]; + pkgCache::VerIterator current; + _profile(Package$initWithVersion$Versions) + current = iterator_.CurrentVer(); + if (!current.end()) + installed_ = (NSString *) StripVersion(current.VerStr()); - if (!version_.end()) - file_ = version_.FileList(); - else { - pkgCache &cache([database_ cache]); - file_ = pkgCache::VerFileIterator(cache, cache.VerFileP); - } + if (!version_.end()) + file_ = version_.FileList(); + else { + pkgCache &cache([database_ cache]); + file_ = pkgCache::VerFileIterator(cache, cache.VerFileP); + } + _end _profile(Package$initWithVersion$Name) - id_.set(pool, iterator_.Name()); + id_.set(pool_, iterator_.Name()); + name_.set(pool, iterator_.Display()); _end - if (!file_.end()) - source_ = [database_ getSource:file_.File()]; - if (source_ != nil) - [source_ retain]; - cached_ = true; - - _profile(Package$initWithVersion$Parse) - pkgRecords::Parser *parser; - - _profile(Package$initWithVersion$Parse$Lookup) - parser = &[database_ records]->Lookup(file_); - _end - - CYString website; - CYString tag; - - _profile(Package$initWithVersion$Parse$Find) - struct { - const char *name_; - CYString *value_; - } names[] = { - {"name", &name_}, - {"icon", &icon_}, - {"depiction", &depiction_}, - {"homepage", &homepage_}, - {"website", &website}, - {"support", &support_}, - {"sponsor", &sponsor_}, - {"author", &author_}, - {"tag", &tag}, - }; - - for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) { - const char *start, *end; - - if (parser->Find(names[i].name_, start, end)) { - CYString &value(*names[i].value_); - _profile(Package$initWithVersion$Parse$Value) - value.set(pool, start, end - start); - _end - } - } - _end - - _profile(Package$initWithVersion$Parse$Tagline) - tagline_.set(pool, parser->ShortDesc()); - _end - - _profile(Package$initWithVersion$Parse$Retain) - if (!homepage_.empty()) - homepage_ = website; - if (homepage_ == depiction_) - homepage_.clear(); - if (!tag.empty()) - tags_ = [[tag componentsSeparatedByString:@", "] retain]; - _end + if (!file_.end()) { + _profile(Package$initWithVersion$Source) + source_ = [database_ getSource:file_.File()]; + if (source_ != nil) + [source_ retain]; + cached_ = true; _end + } _profile(Package$initWithVersion$Tags) - if (tags_ != nil) - for (NSString *tag in tags_) - if ([tag hasPrefix:@"role::"]) { - role_ = [[tag substringFromIndex:6] retain]; - break; - } + pkgCache::TagIterator tag(iterator_.TagList()); + if (!tag.end()) { + tags_ = [[NSMutableArray alloc] initWithCapacity:8]; + do { + const char *name(tag.Name()); + [tags_ addObject:(NSString *)CFCString(name)]; + if (role_ == nil && strncmp(name, "role::", 6) == 0) + role_ = (NSString *) CFCString(name + 6); + ++tag; + } while (!tag.end()); + } _end bool changed(false); @@ -2062,7 +2094,7 @@ struct PackageNameOrdering : metadata_ = [Packages_ objectForKey:key]; if (metadata_ == nil) { - firstSeen_ = [now_ retain]; + firstSeen_ = now_; metadata_ = [[NSMutableDictionary dictionaryWithObjectsAndKeys: firstSeen_, @"FirstSeen", @@ -2105,7 +2137,7 @@ struct PackageNameOrdering : _end _profile(Package$initWithVersion$Section) - section_.set(pool, iterator_.Section()); + section_.set(pool_, iterator_.Section()); _end essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"]; @@ -2930,7 +2962,6 @@ static NSArray *Finishes_; zone_ = NSCreateZone(1024 * 1024, 256 * 1024, NO); apr_pool_create(&pool_, NULL); - sources_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain]; packages_ = [[NSMutableArray alloc] init]; int fds[2]; @@ -3003,7 +3034,10 @@ static NSArray *Finishes_; } - (NSArray *) sources { - return [sources_ allValues]; + NSMutableArray *sources([NSMutableArray arrayWithCapacity:sources_.size()]); + for (SourceMap::const_iterator i(sources_.begin()); i != sources_.end(); ++i) + [sources addObject:i->second]; + return sources; } - (NSArray *) issues { @@ -3075,6 +3109,9 @@ static NSArray *Finishes_; ++era_; } + [packages_ removeAllObjects]; + sources_.clear(); + _error->Discard(); delete list_; @@ -3091,6 +3128,11 @@ static NSArray *Finishes_; delete policy_; policy_ = NULL; + if (now_ != nil) { + [now_ release]; + now_ = nil; + } + cache_.Close(); apr_pool_clear(pool_); @@ -3144,23 +3186,18 @@ static NSArray *Finishes_; } _trace(); - { - std::string lists(_config->FindDir("Dir::State::lists")); - - [sources_ removeAllObjects]; - for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) { - std::vector *indices = (*source)->GetIndexFiles(); - for (std::vector::const_iterator index = indices->begin(); index != indices->end(); ++index) - if (debPackagesIndex *packages = dynamic_cast(*index)) - [sources_ - setObject:[[[Source alloc] initWithMetaIndex:*source] autorelease] - forKey:[NSString stringWithFormat:@"%s%s", - lists.c_str(), - URItoFileName(packages->IndexURI("Packages")).c_str() - ] - ]; - } + + for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) { + 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] autorelease]; + } } + _trace(); { @@ -3169,8 +3206,6 @@ static NSArray *Finishes_; [packages_ release]; packages_ = nil;*/ - [packages_ removeAllObjects]; - _trace(); for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator) @@ -3368,10 +3403,7 @@ static NSArray *Finishes_; } - (Source *) getSource:(pkgCache::PkgFileIterator)file { - if (const char *name = file.FileName()) - if (Source *source = [sources_ objectForKey:[NSString stringWithUTF8String:name]]) - return source; - return nil; + return sources_[file->ID]; } @end @@ -4323,6 +4355,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) setPackage:(Package *)package { [self clearPackage]; + [package parse]; Source *source = [package source]; @@ -4453,14 +4486,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } + (int) heightForPackage:(Package *)package { - NSString *tagline([package shortDescription]); - int height = tagline == nil || [tagline length] == 0 ? -17 : 0; -#ifdef USE_BADGES - if ([package hasMode] || [package half]) - return height + 96; - else -#endif - return height + 73; + return 73; } @end @@ -4845,6 +4871,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [buttons_ removeAllObjects]; if (package != nil) { + [package parse]; + package_ = [package retain]; name_ = [[package id] retain]; commercial_ = [package isCommercial];