X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/237c3d1c44503c9be4762b43a841b011f5faeebb..1a83afc616cd6901ebff9adabe4f397ed8dfaf8d:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 32031c46..50fcb6fe 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -159,7 +159,7 @@ class ProfileTime { void Print() { if (total_ != 0) - std::cerr << std::setw(5) << count_ << ", " << std::setw(7) << total_ << " : " << name_ << std::endl; + std::cerr << std::setw(7) << count_ << ", " << std::setw(7) << total_ << " : " << name_ << std::endl; total_ = 0; count_ = 0; } @@ -205,7 +205,7 @@ extern NSString *Cydia_; #define ForRelease 1 #define TraceLogging (1 && !ForRelease) -#define HistogramInsertionSort (!ForRelease ? 0 : 0) +#define HistogramInsertionSort (0 && !ForRelease) #define ProfileTimes (0 && !ForRelease) #define ForSaurik (0 && !ForRelease) #define LogBrowser (0 && !ForRelease) @@ -1503,7 +1503,10 @@ static void PackageImport(const void *key, const void *value, void *context) { base_.set(pool, file); pkgAcquire acquire; + _profile(Source$setMetaIndex$GetIndexes) dindex->GetIndexes(&acquire, true); + _end + _profile(Source$setMetaIndex$DescURI) for (pkgAcquire::ItemIterator item(acquire.ItemsBegin()); item != acquire.ItemsEnd(); item++) { std::string file((*item)->DescURI()); files_.insert(file); @@ -1514,6 +1517,7 @@ static void PackageImport(const void *key, const void *value, void *context) { files_.insert(file + ".gz"); files_.insert(file + "Index"); } + _end FileFd fd; if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly)) @@ -1568,7 +1572,9 @@ static void PackageImport(const void *key, const void *value, void *context) { database_ = database; index_ = index; + _profile(Source$initWithMetaIndex$setMetaIndex) [self setMetaIndex:index inPool:pool]; + _end } return self; } @@ -3013,6 +3019,10 @@ struct PackageNameOrdering : return source_ == (Source *) [NSNull null] ? nil : source_; } +- (uint32_t) updated { + return std::numeric_limits::max() - updated_; +} + - (uint32_t) rank { return rank_; } @@ -3585,18 +3595,26 @@ class CydiaLogCleaner : NSString *title(UCLocalize("DATABASE")); list_ = new pkgSourceList(); + _profile(reloadDataWithInvocation$ReadMainList) if ([self popErrorWithTitle:title forOperation:list_->ReadMainList()]) return; + _end + _profile(reloadDataWithInvocation$Source$initWithMetaIndex) for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) { Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:pool_] autorelease]); [sourceList_ addObject:object]; } + _end _trace(); OpProgress progress; + bool opened; open: - if (!cache_.Open(progress, true)) { + _profile(reloadDataWithInvocation$pkgCacheFile) + opened = cache_.Open(progress, true); + _end + if (!opened) { // XXX: what if there are errors, but Open() == true? this should be merged with popError: while (!_error->empty()) { std::string error; @@ -3643,20 +3661,26 @@ class CydiaLogCleaner : return; } + _profile(reloadDataWithInvocation$pkgApplyStatus) if ([self popErrorWithTitle:title forOperation:pkgApplyStatus(cache_)]) return; + _end if (cache_->BrokenCount() != 0) { + _profile(pkgApplyStatus$pkgFixBroken) if ([self popErrorWithTitle:title forOperation:pkgFixBroken(cache_)]) return; + _end if (cache_->BrokenCount() != 0) { [delegate_ addProgressEventOnMainThread:[CydiaProgressEvent eventWithMessage:UCLocalize("STILL_BROKEN_EX") ofType:kCydiaProgressEventTypeError] forTask:title]; return; } + _profile(pkgApplyStatus$pkgMinimizeUpgrade) if ([self popErrorWithTitle:title forOperation:pkgMinimizeUpgrade(cache_)]) return; + _end } for (Source *object in (id) sourceList_) { @@ -3676,14 +3700,13 @@ class CydiaLogCleaner : packages.reserve(std::max(10000U, [packages_ count] + 1000)); packages_ = nil;*/ - _trace(); - + _profile(reloadDataWithInvocation$packageWithIterator) for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator) if (Package *package = [Package packageWithIterator:iterator withZone:zone_ inPool:pool_ database:self]) //packages.push_back(package); CFArrayAppendValue(packages_, CFRetain(package)); + _end - _trace(); /*if (packages.empty()) packages_ = [[NSArray alloc] init]; @@ -3691,35 +3714,43 @@ class CydiaLogCleaner : packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()]; _trace();*/ - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(16)]; + _profile(reloadDataWithInvocation$radix$8) + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(8)]; + _end + + _profile(reloadDataWithInvocation$radix$4) [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(4)]; - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; + _end - /*_trace(); - PrintTimes(); - _trace();*/ + _profile(reloadDataWithInvocation$radix$0) + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; + _end - _trace(); + _profile(reloadDataWithInvocation$insertion) + CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&PackageNameCompare), NULL); + _end - /*if (!packages.empty()) - CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast(&PackageNameCompare_), NULL);*/ - //std::sort(packages.begin(), packages.end(), PackageNameOrdering()); + /*_profile(reloadDataWithInvocation$CFQSortArray) + CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast(&PackageNameCompare_), NULL); + _end*/ - //CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast(&PackageNameCompare), NULL); + /*_profile(reloadDataWithInvocation$stdsort) + std::sort(packages.begin(), packages.end(), PackageNameOrdering()); + _end*/ - CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&PackageNameCompare), NULL); + /*_profile(reloadDataWithInvocation$CFArraySortValues) + CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast(&PackageNameCompare), NULL); + _end*/ - //[packages_ sortUsingFunction:reinterpret_cast(&PackageNameCompare) context:NULL]; + /*_profile(reloadDataWithInvocation$sortUsingFunction) + [packages_ sortUsingFunction:reinterpret_cast(&PackageNameCompare) context:NULL]; + _end*/ - _trace(); size_t count(CFArrayGetCount(packages_)); MetaFile_->active_ = count; - for (size_t index(0); index != count; ++index) [(Package *) CFArrayGetValueAtIndex(packages_, index) setIndex:index]; - - _trace(); } } } @@ -6473,7 +6504,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [(UITableView *) list_ setDataSource:self]; [list_ reloadData]; _end -} } +} + + PrintTimes(); +} - (NSArray *) sectionsForPackages:(NSMutableArray *)packages { NSMutableArray *sections([NSMutableArray arrayWithCapacity:16]); @@ -7462,7 +7496,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi action:@selector(upgradeButtonClicked) ] autorelease]) animated:YES]; - PrintTimes(); return sections; } @@ -7808,6 +7841,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi /* Installed Controller {{{ */ @interface InstalledController : FilteredPackageListController { + bool sectioned_; } - (id) initWithDatabase:(Database *)database; @@ -7825,18 +7859,41 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi return [NSURL URLWithString:@"cydia://installed"]; } +- (bool) showsSections { + return sectioned_; +} + +- (void) useUpdated { + sectioned_ = false; + +@synchronized (self) { + [self setFilter:[](Package *package) { + return ![package uninstalled] && package->role_ < 7; + }]; + + [self setSorter:[](NSMutableArray *packages) { + [packages radixSortUsingSelector:@selector(updated)]; + }]; +} } + - (void) useFilter:(UISegmentedControl *)segmented { - bool simple([segmented selectedSegmentIndex] == 0); + NSInteger selected([segmented selectedSegmentIndex]); + if (selected == 2) + return [self useUpdated]; + bool simple(selected == 0); + sectioned_ = true; @synchronized (self) { [self setFilter:[=](Package *package) { return ![package uninstalled] && package->role_ <= (simple ? 1 : 3); }]; + + [self setSorter:nullptr]; } } - (id) initWithDatabase:(Database *)database { if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED")]) != nil) { - UISegmentedControl *segmented([[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:UCLocalize("SIMPLE"), UCLocalize("EXPERT"), nil]] autorelease]); + UISegmentedControl *segmented([[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:UCLocalize("USER"), UCLocalize("EXPERT"), UCLocalize("RECENT"), nil]] autorelease]); [segmented setSelectedSegmentIndex:0]; [segmented setSegmentedControlStyle:UISegmentedControlStyleBar]; [[self navigationItem] setTitleView:segmented]; @@ -8839,6 +8896,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) reloadDataWithInvocation:(NSInvocation *)invocation { +_profile(reloadDataWithInvocation) @synchronized (self) { UIProgressHUD *hud(loaded_ ? [self addProgressHUD] : nil); if (hud != nil) @@ -8851,6 +8909,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [essential_ removeAllObjects]; [broken_ removeAllObjects]; + _profile(reloadDataWithInvocation$Essential) NSArray *packages([database_ packages]); for (Package *package in packages) { if ([package half]) @@ -8861,6 +8920,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi ++changes; } } + _end UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:2] tabBarItem]; if (changes != 0) { @@ -8880,7 +8940,11 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (hud != nil) [self removeProgressHUD:hud]; -} } +} +_end + + PrintTimes(); +} - (void) updateData { [self _updateData]; @@ -9624,8 +9688,6 @@ _trace(); [self reloadDataWithInvocation:nil]; [self refreshIfPossible]; - PrintTimes(); - [self disemulate]; int savedIndex = [[Metadata_ objectForKey:@"InterfaceIndex"] intValue];