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:
25
lib/plist.c
25
lib/plist.c
@ -221,8 +221,7 @@ array_replace_dict(xbps_array_t array,
|
||||
bool bypattern)
|
||||
{
|
||||
xbps_object_t obj;
|
||||
const char *curpkgver;
|
||||
char curpkgname[XBPS_NAME_SIZE];
|
||||
const char *pkgver, *pkgname;
|
||||
|
||||
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
|
||||
assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
|
||||
@ -230,26 +229,24 @@ array_replace_dict(xbps_array_t array,
|
||||
|
||||
for (unsigned int i = 0; i < xbps_array_count(array); i++) {
|
||||
obj = xbps_array_get(array, i);
|
||||
if (obj == NULL)
|
||||
if (obj == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver)) {
|
||||
continue;
|
||||
}
|
||||
if (bypattern) {
|
||||
/* pkgpattern match */
|
||||
xbps_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &curpkgver);
|
||||
if (xbps_pkgpattern_match(curpkgver, str)) {
|
||||
if (!xbps_array_set(array, i, dict))
|
||||
if (xbps_pkgpattern_match(pkgver, str)) {
|
||||
if (!xbps_array_set(array, i, dict)) {
|
||||
return EINVAL;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* pkgname match */
|
||||
xbps_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &curpkgver);
|
||||
if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
|
||||
abort();
|
||||
}
|
||||
if (strcmp(curpkgname, str) == 0) {
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
if (strcmp(pkgname, str) == 0) {
|
||||
if (!xbps_array_set(array, i, dict)) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user