From: Jay Freeman (saurik) Date: Thu, 22 Jan 2009 06:02:46 +0000 (+0000) Subject: Welcome to unsafe optimizations. X-Git-Url: https://git.saurik.com/cydia.git/commitdiff_plain/142bd2db7f2ea88a8e2d35227005c14092e19d38?ds=sidebyside Welcome to unsafe optimizations. --- diff --git a/Cydia.mm b/Cydia.mm index 758a99e7..7e4f33fe 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -129,6 +129,7 @@ class ProfileTime { private: const char *name_; uint64_t total_; + uint64_t count_; public: ProfileTime(const char *name) : @@ -140,12 +141,14 @@ class ProfileTime { void AddTime(uint64_t time) { total_ += time; + ++count_; } void Print() { if (total_ != 0) - std::cerr << std::setw(7) << total_ << " : " << name_ << std::endl; + std::cerr << std::setw(5) << count_ << ", " << std::setw(7) << total_ << " : " << name_ << std::endl; total_ = 0; + count_ = 0; } }; @@ -4375,6 +4378,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* Filtered Package Table {{{ */ @interface FilteredPackageTable : PackageTable { SEL filter_; + IMP imp_; id object_; } @@ -4402,7 +4406,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (bool) hasPackage:(Package *)package { - return [package valid] && (*reinterpret_cast(&objc_msgSend))(package, filter_, object_); + _profile(FilteredPackageTable$hasPackage) + return [package valid] && (*reinterpret_cast(imp_))(package, filter_, object_); + _end } - (id) initWithBook:(RVBook *)book database:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object { @@ -4410,6 +4416,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { filter_ = filter; object_ = object == nil ? nil : [object retain]; + /* XXX: this is an unsafe optimization of doomy hell */ + Method method = class_getInstanceMethod([Package class], filter); + imp_ = method_getImplementation(method); + _assert(imp_ != NULL); + [self reloadData]; } return self; }