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:
Juan RP
2020-02-21 09:08:22 +01:00
parent 701132071d
commit 06c9891ae3
28 changed files with 960 additions and 742 deletions

View File

@ -330,8 +330,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
{
xbps_array_t allkeys;
xbps_dictionary_t alternatives, pkg_alternatives;
const char *pkgver;
char pkgname[XBPS_NAME_SIZE];
const char *pkgver, *pkgname;
bool update = false;
int rv = 0;
@ -346,8 +345,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
return 0;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
return EINVAL;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
xbps_dictionary_get_bool(pkgd, "alternatives-update", &update);
@ -472,7 +470,7 @@ prune_altgroup(struct xbps_handle *xhp, xbps_dictionary_t repod,
static void
remove_obsoletes(struct xbps_handle *xhp, char *pkgname, const char *pkgver,
remove_obsoletes(struct xbps_handle *xhp, const char *pkgname, const char *pkgver,
xbps_dictionary_t pkgdb_alts, xbps_dictionary_t repod)
{
xbps_array_t allkeys;
@ -531,8 +529,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
{
xbps_array_t allkeys;
xbps_dictionary_t alternatives, pkg_alternatives;
const char *pkgver;
char pkgname[XBPS_NAME_SIZE];
const char *pkgver, *pkgname;
int rv = 0;
assert(xhp);
@ -550,8 +547,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
assert(alternatives);
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
return EINVAL;
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
/*
* Compare alternatives from pkgdb and repo and then remove obsolete