Package Kit: Refactor BRepositoryCache to have GetPackageInfos(callback)...

... instead of GetIterator(). This allows us to avoid loading the
cache entirely in SetTo(), and allows consumers to read the cache
much more efficiently than loading it all into memory and then
freeing it again afterwards.

This technically breaks API/ABI, however the Package Kit APIs
are not considered stable (I don't think.)

All consumers adjusted. As we build the host tools with modern GCC
only, I made update_package_requires use a C++11 lambda function.
All others use out-of-line static methods.

"time pkgman list-repos -v" (which has to read the whole cache)
is ~0.5s before this change, and ~0.25s after this change,
on my test VM.

Change-Id: I6976b4cf5eb846fc925ed199dc00eb227fc81344
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10247
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Andrew Lindesay <[email protected]>
This commit is contained in:
Augustin Cavalier
2026-01-21 20:27:13 +00:00
committed by waddlesplash
parent 506e7c5ef7
commit 4ed2896398
7 changed files with 92 additions and 72 deletions
+6 -7
View File
@@ -18,7 +18,7 @@ namespace BPackageKit {
class BRepositoryCache {
public:
typedef BPackageInfoSet::Iterator Iterator;
typedef bool (*GetPackageInfosCallback)(void* /* context */, const BPackageInfo& info);
public:
BRepositoryCache();
@@ -30,20 +30,19 @@ public:
const BEntry& Entry() const;
bool IsUserSpecific() const;
void SetIsUserSpecific(bool isUserSpecific);
uint32 CountPackages() const;
Iterator GetIterator() const;
status_t GetPackageInfos(GetPackageInfosCallback callback, void* context) const;
private:
struct RepositoryContentHandler;
status_t _ReadCache(const BPath& repositoryCachePath,
BRepositoryInfo& repositoryInfo,
GetPackageInfosCallback callback, void* context) const;
private:
BEntry fEntry;
BRepositoryInfo fInfo;
bool fIsUserSpecific;
BPackageInfoSet fPackages;
};