xbps_transaction_*: multiple performance improvements (v2).
This commit implements multiple performance improvements to the transaction code: - Don't process xbps_pkg_name() N times each time we access its package dictionary (via pkgdb or rpool), just do it once at xbps_pkgdb_init() time. At pkgdb init time, it just creates a property in pkgdb, "pkgname". At rpool time, each time a package is accessed, the "pkgname" string property is added. - The package transaction dictionary contains the "transaction" object to know what's the pkg type. This has been changed to an uint8, this simplifies the logic and it's faster than checking a string object. See xbps_trans_type_t and xbps_transaction_pkg_type(). - Fixed the issue that was marked with XXX in transaction shlibs checking code. This has been fixed and improved and resources are now just freed as expected. - Simplified random code all over the place, avoiding unnecessary allocations or operations. - Rename some transaction files to have a better description. This is my first rototill to the code in 2020.
This commit is contained in:
69
lib/repo.c
69
lib/repo.c
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2012-2015 Juan Romero Pardines.
|
||||
* Copyright (c) 2012-2020 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -391,45 +391,70 @@ xbps_dictionary_t
|
||||
xbps_repo_get_virtualpkg(struct xbps_repo *repo, const char *pkg)
|
||||
{
|
||||
xbps_dictionary_t pkgd;
|
||||
const char *pkgver;
|
||||
char pkgname[XBPS_NAME_SIZE] = {0};
|
||||
|
||||
assert(repo);
|
||||
assert(pkg);
|
||||
|
||||
if (repo->idx == NULL)
|
||||
if (!repo || !repo->idx || !pkg) {
|
||||
return NULL;
|
||||
|
||||
}
|
||||
pkgd = xbps_find_virtualpkg_in_dict(repo->xhp, repo->idx, pkg);
|
||||
if (pkgd) {
|
||||
xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri);
|
||||
if (!pkgd) {
|
||||
return NULL;
|
||||
}
|
||||
if (xbps_dictionary_get(pkgd, "repository") && xbps_dictionary_get(pkgd, "pkgname")) {
|
||||
return pkgd;
|
||||
}
|
||||
return NULL;
|
||||
if (!xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!xbps_dictionary_set_cstring(pkgd, "pkgname", pkgname)) {
|
||||
return NULL;
|
||||
}
|
||||
return pkgd;
|
||||
}
|
||||
|
||||
xbps_dictionary_t
|
||||
xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
|
||||
{
|
||||
xbps_dictionary_t pkgd;
|
||||
xbps_dictionary_t pkgd = NULL;
|
||||
const char *pkgver;
|
||||
char pkgname[XBPS_NAME_SIZE] = {0};
|
||||
|
||||
assert(repo);
|
||||
assert(pkg);
|
||||
|
||||
if (repo->idx == NULL)
|
||||
if (!repo || !repo->idx || !pkg) {
|
||||
return NULL;
|
||||
|
||||
}
|
||||
/* Try matching vpkg from configuration files */
|
||||
if ((pkgd = xbps_find_virtualpkg_in_conf(repo->xhp, repo->idx, pkg))) {
|
||||
xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri);
|
||||
return pkgd;
|
||||
goto add;
|
||||
}
|
||||
/* ... otherwise match a real pkg */
|
||||
pkgd = xbps_find_pkg_in_dict(repo->idx, pkg);
|
||||
if (pkgd) {
|
||||
xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri);
|
||||
if ((pkgd = xbps_find_pkg_in_dict(repo->idx, pkg))) {
|
||||
goto add;
|
||||
}
|
||||
return NULL;
|
||||
add:
|
||||
if (xbps_dictionary_get(pkgd, "repository") && xbps_dictionary_get(pkgd, "pkgname")) {
|
||||
return pkgd;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (!xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!xbps_dictionary_set_cstring(pkgd, "pkgname", pkgname)) {
|
||||
return NULL;
|
||||
}
|
||||
return pkgd;
|
||||
}
|
||||
|
||||
xbps_dictionary_t
|
||||
|
Reference in New Issue
Block a user