xbps_sort_pkg_deps: optimize one more time, it is 5% faster approx.
This commit is contained in:
parent
be5ff1d934
commit
a47d030851
@ -56,6 +56,7 @@ xbps_sort_pkg_deps(void)
|
|||||||
const char *pkgname, *pkgver, *str;
|
const char *pkgname, *pkgver, *str;
|
||||||
char *pkgnamedep;
|
char *pkgnamedep;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
bool done;
|
||||||
|
|
||||||
if ((transd = xbps_transaction_dictionary_get()) == NULL)
|
if ((transd = xbps_transaction_dictionary_get()) == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -78,12 +79,20 @@ xbps_sort_pkg_deps(void)
|
|||||||
prop_dictionary_set(transd, "packages", sorted);
|
prop_dictionary_set(transd, "packages", sorted);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* The sorted array should have the same capacity than
|
||||||
|
* all objects in the unsorted array.
|
||||||
|
*/
|
||||||
ndeps = prop_array_count(unsorted);
|
ndeps = prop_array_count(unsorted);
|
||||||
|
if (!prop_array_ensure_capacity(sorted, ndeps)) {
|
||||||
|
xbps_error_printf("failed to set capacity to the sorted "
|
||||||
|
"pkgdeps array\n");
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
iter = prop_array_iterator(unsorted);
|
iter = prop_array_iterator(unsorted);
|
||||||
if (iter == NULL) {
|
if (iter == NULL) {
|
||||||
prop_object_release(sorted);
|
rv = ENOMEM;
|
||||||
return ENOMEM;
|
goto out;
|
||||||
}
|
}
|
||||||
again:
|
again:
|
||||||
/*
|
/*
|
||||||
@ -93,14 +102,16 @@ again:
|
|||||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||||
xbps_dbg_printf("Sorting package '%s': ", pkgver);
|
xbps_dbg_printf("Sorting package '%s': ", pkgver);
|
||||||
|
/*
|
||||||
if (xbps_find_pkg_in_dict_by_name(transd,
|
* Check if package was sorted previously and skip.
|
||||||
"packages", pkgname)) {
|
*/
|
||||||
|
done = false;
|
||||||
|
prop_dictionary_get_bool(obj, "sorted", &done);
|
||||||
|
if (done) {
|
||||||
xbps_dbg_printf_append("skipping, already queued.\n",
|
xbps_dbg_printf_append("skipping, already queued.\n",
|
||||||
pkgname);
|
pkgname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Packages that don't have deps go unsorted, because
|
* Packages that don't have deps go unsorted, because
|
||||||
* it doesn't matter.
|
* it doesn't matter.
|
||||||
@ -110,11 +121,7 @@ again:
|
|||||||
xbps_dbg_printf_append("added (no rundeps) into "
|
xbps_dbg_printf_append("added (no rundeps) into "
|
||||||
"the sorted queue.\n");
|
"the sorted queue.\n");
|
||||||
prop_array_add(sorted, obj);
|
prop_array_add(sorted, obj);
|
||||||
if (!xbps_remove_pkg_from_dict(transd,
|
prop_dictionary_set_bool(obj, "sorted", true);
|
||||||
"unsorted_deps", pkgname)) {
|
|
||||||
xbps_dbg_printf("can't remove %s from "
|
|
||||||
"unsorted_deps array!\n", pkgname);
|
|
||||||
}
|
|
||||||
cnt++;
|
cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -123,7 +130,6 @@ again:
|
|||||||
rv = ENOMEM;
|
rv = ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Iterate over the run_depends array, and find out if they
|
* Iterate over the run_depends array, and find out if they
|
||||||
* were already added in the sorted list.
|
* were already added in the sorted list.
|
||||||
@ -164,11 +170,7 @@ again:
|
|||||||
/* Add dependency if all its required deps are already added */
|
/* Add dependency if all its required deps are already added */
|
||||||
if (prop_array_count(rundeps) == rundepscnt) {
|
if (prop_array_count(rundeps) == rundepscnt) {
|
||||||
prop_array_add(sorted, obj);
|
prop_array_add(sorted, obj);
|
||||||
if (!xbps_remove_pkg_from_dict(transd,
|
prop_dictionary_set_bool(obj, "sorted", true);
|
||||||
"unsorted_deps", pkgname)) {
|
|
||||||
xbps_dbg_printf("can't remove %s from "
|
|
||||||
"unsorted_deps array!\n", pkgname);
|
|
||||||
}
|
|
||||||
xbps_dbg_printf("Added package '%s' to the sorted "
|
xbps_dbg_printf("Added package '%s' to the sorted "
|
||||||
"queue (all rundeps satisfied).\n\n", pkgver);
|
"queue (all rundeps satisfied).\n\n", pkgver);
|
||||||
rundepscnt = 0;
|
rundepscnt = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user