]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Add a _trace() to applicationDidFinishLaunching:.
[cydia.git] / MobileCydia.mm
index 10e8199f065e4574c87b0d41607b9a9c458cb2c4..d6adebabcdab5d134d16279ea7b55783603d80c5 100644 (file)
@@ -1101,9 +1101,7 @@ NSString *SizeString(double size) {
 
 static _finline const char *StripVersion_(const char *version) {
     const char *colon(strchr(version, ':'));
-    if (colon != NULL)
-        version = colon + 1;
-    return version;
+    return colon == NULL ? version : colon + 1;
 }
 
 NSString *LocalizeSection(NSString *section) {
@@ -1432,7 +1430,6 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 struct PackageValue :
     Cytore::Block
 {
-    Cytore::Offset<void> reserved_;
     Cytore::Offset<PackageValue> next_;
 
     uint32_t index_ : 23;
@@ -1452,14 +1449,13 @@ struct PackageValue :
 struct MetaValue :
     Cytore::Block
 {
-    Cytore::Offset<void> reserved_;
     Cytore::Offset<PackageValue> packages_[1 << 16];
 };
 
 static Cytore::File<MetaValue> MetaFile_;
 // }}}
 // Cytore Helper Functions {{{
-static PackageValue *PackageFind(const char *name, size_t length, Cytore::Offset<PackageValue> *cache = NULL) {
+static PackageValue *PackageFind(const char *name, size_t length) {
     SplitHash nhash = { hashlittle(name, length) };
 
     PackageValue *metadata;
@@ -1480,9 +1476,6 @@ static PackageValue *PackageFind(const char *name, size_t length, Cytore::Offset
         }
     }
 
-    if (cache != NULL)
-        *cache = *offset;
-
     return metadata;
 }
 
@@ -1831,34 +1824,35 @@ struct ParsedPackage {
 };
 
 @interface Package : NSObject {
-    unsigned era_;
+    uint32_t era_ : 29;
+    uint32_t essential_ : 1;
+    uint32_t obsolete_ : 1;
+    uint32_t ignored_ : 1;
+
     apr_pool_t *pool_;
 
+    _transient Database *database_;
+
     pkgCache::VerIterator version_;
     pkgCache::PkgIterator iterator_;
-    _transient Database *database_;
     pkgCache::VerFileIterator file_;
 
-    Source *source_;
-    ParsedPackage *parsed_;
+    CYString id_;
+    CYString name_;
+
+    CYString latest_;
+    CYString installed_;
 
     CYString section_;
     _transient NSString *section$_;
-    bool essential_;
-    bool obsolete_;
 
-    CYString latest_;
-    CYString installed_;
+    Source *source_;
 
-    CYString id_;
-    CYString name_;
+    PackageValue *metadata_;
+    ParsedPackage *parsed_;
 
     NSMutableArray *tags_;
     NSString *role_;
-
-    Cytore::Offset<PackageValue> metadata_;
-
-    bool ignored_;
 }
 
 - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
@@ -1930,6 +1924,8 @@ struct ParsedPackage {
 - (NSArray *) purposes;
 - (bool) isCommercial;
 
+- (void) setIndex:(size_t)index;
+
 - (CYString &) cyname;
 
 - (uint32_t) compareBySection:(NSArray *)sections;
@@ -2189,27 +2185,17 @@ struct PackageNameOrdering :
 - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
     if ((self = [super init]) != nil) {
     _profile(Package$initWithVersion)
-        era_ = [database era];
         pool_ = pool;
 
-        version_ = version;
-
-        _profile(Package$initWithVersion$ParentPkg)
-            iterator_ = version.ParentPkg();
-        _end
-
         database_ = database;
+        era_ = [database era];
 
-        _profile(Package$initWithVersion$Latest)
-            latest_.set(NULL, StripVersion_(version_.VerStr()));
-        _end
+        version_ = version;
 
-        pkgCache::VerIterator current;
-        _profile(Package$initWithVersion$Versions)
-            current = iterator_.CurrentVer();
-            if (!current.end())
-                installed_.set(NULL, StripVersion_(current.VerStr()));
+        pkgCache::PkgIterator iterator(version.ParentPkg());
+        iterator_ = iterator;
 
+        _profile(Package$initWithVersion$Version)
             if (!version_.end())
                 file_ = version_.FileList();
             else {
@@ -2218,12 +2204,18 @@ struct PackageNameOrdering :
             }
         _end
 
-        _profile(Package$initWithVersion$Name)
-            id_.set(NULL, iterator_.Name());
-            name_.set(NULL, iterator_.Display());
+        _profile(Package$initWithVersion$Cache)
+            id_.set(NULL, iterator.Name());
+            name_.set(NULL, iterator.Display());
+
+            latest_.set(NULL, StripVersion_(version_.VerStr()));
+
+            pkgCache::VerIterator current(iterator.CurrentVer());
+            if (!current.end())
+                installed_.set(NULL, StripVersion_(current.VerStr()));
         _end
 
-        _profile(Package$initWithVersion$lowercaseString)
+        _profile(Package$initWithVersion$Lower)
             // XXX: do not use tolower() as this is not locale-specific? :(
             char *data(id_.data());
             for (size_t i(0), e(id_.size()); i != e; ++i)
@@ -2237,7 +2229,7 @@ struct PackageNameOrdering :
         _end
 
         _profile(Package$initWithVersion$Tags)
-            pkgCache::TagIterator tag(iterator_.TagList());
+            pkgCache::TagIterator tag(iterator.TagList());
             if (!tag.end()) {
                 tags_ = [[NSMutableArray alloc] initWithCapacity:8];
                 do {
@@ -2260,7 +2252,8 @@ struct PackageNameOrdering :
         _end
 
         _profile(Package$initWithVersion$Metadata)
-            PackageValue *metadata(PackageFind(id_.data(), id_.size(), &metadata_));
+            PackageValue *metadata(PackageFind(id_.data(), id_.size()));
+            metadata_ = metadata;
 
             const char *latest(version_.VerStr());
             size_t length(strlen(latest));
@@ -2282,14 +2275,13 @@ struct PackageNameOrdering :
         _end
 
         _profile(Package$initWithVersion$Section)
-            section_.set(NULL, iterator_.Section());
+            section_.set(NULL, iterator.Section());
         _end
 
-        _profile(Package$initWithVersion$hasTag)
-            essential_ |= ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES);
+        _profile(Package$initWithVersion$Flags)
+            essential_ |= ((iterator->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES);
+            ignored_ = iterator->SelectedState == pkgCache::State::Hold;
         _end
-
-        ignored_ = iterator_->SelectedState == pkgCache::State::Hold;
     _end } return self;
 }
 
@@ -2303,12 +2295,26 @@ struct PackageNameOrdering :
     if (version.end())
         return nil;
 
-    return [[[Package alloc]
-        initWithVersion:version
-        withZone:zone
-        inPool:pool
-        database:database
-    ] autorelease];
+    Package *package;
+
+    _profile(Package$packageWithIterator$Allocate)
+        package = [Package allocWithZone:zone];
+    _end
+
+    _profile(Package$packageWithIterator$Initialize)
+        package = [package
+            initWithVersion:version
+            withZone:zone
+            inPool:pool
+            database:database
+        ];
+    _end
+
+    _profile(Package$packageWithIterator$Autorelease)
+        package = [package autorelease];
+    _end
+
+    return package;
 }
 
 - (pkgCache::PkgIterator) iterator {
@@ -2413,7 +2419,7 @@ struct PackageNameOrdering :
 }
 
 - (PackageValue *) metadata {
-    return &MetaFile_.Get(metadata_);
+    return metadata_;
 }
 
 - (time_t) seen {
@@ -2778,6 +2784,11 @@ struct PackageNameOrdering :
     return [self hasTag:@"cydia::commercial"];
 }
 
+- (void) setIndex:(size_t)index {
+    if (metadata_->index_ != index)
+        metadata_->index_ = index;
+}
+
 - (CYString &) cyname {
     return name_.empty() ? id_ : name_;
 }
@@ -3461,6 +3472,12 @@ static NSString *Warning_;
         //[packages_ sortUsingFunction:reinterpret_cast<NSComparisonResult (*)(id, id, void *)>(&PackageNameCompare) context:NULL];
 
         _trace();
+
+        size_t count(CFArrayGetCount(packages_));
+        for (size_t index(0); index != count; ++index)
+            [(Package *) CFArrayGetValueAtIndex(packages_, index) setIndex:index];
+
+        _trace();
     }
 } } CYPoolEnd() _trace(); }
 
@@ -4982,14 +4999,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) onSwitch:(id)sender {
-    NSMutableDictionary *metadata = [Sections_ objectForKey:basic_];
+    NSMutableDictionary *metadata([Sections_ objectForKey:basic_]);
     if (metadata == nil) {
         metadata = [NSMutableDictionary dictionaryWithCapacity:2];
         [Sections_ setObject:metadata forKey:basic_];
     }
 
-    Changed_ = true;
     [metadata setObject:[NSNumber numberWithBool:([switch_ isOn] == NO)] forKey:@"Hidden"];
+    Changed_ = true;
 }
 
 - (void) setSection:(Section *)section editing:(BOOL)editing {
@@ -7541,7 +7558,6 @@ freeing the view controllers on tab change */
         nil];
 
         [Metadata_ setObject:Settings_ forKey:@"Settings"];
-
         Changed_ = true;
 
         if (rolling)
@@ -8044,21 +8060,24 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) _saveConfig {
+    _trace();
+    MetaFile_.Sync();
+    _trace();
+
     if (Changed_) {
-        _trace();
         NSString *error(nil);
+
         if (NSData *data = [NSPropertyListSerialization dataFromPropertyList:Metadata_ format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error]) {
             _trace();
             NSError *error(nil);
             if (![data writeToFile:@"/var/lib/cydia/metadata.plist" options:NSAtomicWrite error:&error])
                 NSLog(@"failure to save metadata data: %@", error);
             _trace();
+
+            Changed_ = false;
         } else {
             NSLog(@"failure to serialize metadata: %@", error);
-            return;
         }
-
-        Changed_ = false;
     }
 }
 
@@ -8735,6 +8754,7 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) applicationDidFinishLaunching:(id)unused {
+_trace();
     [CYBrowserController _initialize];
 
     [NSURLProtocol registerClass:[CydiaURLProtocol class]];