sortdeps: use a SIMPLEQ rather than a TAILQ, it's enough and faster.

--HG--
extra : convert_revision : b42935d05f31a74838140ef46293b65f9f0cb07d
This commit is contained in:
Juan RP 2009-02-14 05:45:04 +01:00
parent ee309578f7
commit 5a894ad5e5

View file

@ -33,15 +33,15 @@
#include <xbps_api.h> #include <xbps_api.h>
struct sorted_dependency { struct sorted_dependency {
TAILQ_ENTRY(sorted_dependency) chain; SIMPLEQ_ENTRY(sorted_dependency) chain;
prop_dictionary_t dict; prop_dictionary_t dict;
prop_array_t reqby; prop_array_t reqby;
size_t idx; size_t idx;
size_t prio; size_t prio;
}; };
static TAILQ_HEAD(sdep_head, sorted_dependency) sdep_list = static SIMPLEQ_HEAD(sdep_head, sorted_dependency) sdep_list =
TAILQ_HEAD_INITIALIZER(sdep_list); SIMPLEQ_HEAD_INITIALIZER(sdep_list);
static ssize_t static ssize_t
find_pkgdict_with_highest_prio(prop_array_t array, uint32_t *maxprio, find_pkgdict_with_highest_prio(prop_array_t array, uint32_t *maxprio,
@ -97,7 +97,7 @@ find_sorteddep_with_highest_prio(void)
size_t maxprio = 0; size_t maxprio = 0;
size_t curidx = 0, idx = 0; size_t curidx = 0, idx = 0;
TAILQ_FOREACH(sdep, &sdep_list, chain) { SIMPLEQ_FOREACH(sdep, &sdep_list, chain) {
if (maxprio <= sdep->prio) { if (maxprio <= sdep->prio) {
curidx = idx; curidx = idx;
maxprio = sdep->prio; maxprio = sdep->prio;
@ -106,7 +106,7 @@ find_sorteddep_with_highest_prio(void)
} }
idx = 0; idx = 0;
TAILQ_FOREACH(sdep, &sdep_list, chain) { SIMPLEQ_FOREACH(sdep, &sdep_list, chain) {
if (idx == curidx) if (idx == curidx)
break; break;
idx++; idx++;
@ -121,7 +121,7 @@ find_sorteddep_by_name(const char *pkgname)
struct sorted_dependency *sdep; struct sorted_dependency *sdep;
const char *curname; const char *curname;
TAILQ_FOREACH(sdep, &sdep_list, chain) { SIMPLEQ_FOREACH(sdep, &sdep_list, chain) {
prop_dictionary_get_cstring_nocopy(sdep->dict, prop_dictionary_get_cstring_nocopy(sdep->dict,
"pkgname", &curname); "pkgname", &curname);
if (strcmp(pkgname, curname) == 0) if (strcmp(pkgname, curname) == 0)
@ -191,7 +191,7 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
reqby = prop_dictionary_get(dict, "required_by"); reqby = prop_dictionary_get(dict, "required_by");
if (reqby && prop_array_count(reqby) > 0) if (reqby && prop_array_count(reqby) > 0)
sdep->reqby = prop_array_copy(reqby); sdep->reqby = prop_array_copy(reqby);
TAILQ_INSERT_TAIL(&sdep_list, sdep, chain); SIMPLEQ_INSERT_TAIL(&sdep_list, sdep, chain);
prop_array_remove(unsorted, curidx); prop_array_remove(unsorted, curidx);
maxprio = 0; maxprio = 0;
cnt++; cnt++;
@ -224,7 +224,7 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
reqby = prop_dictionary_get(dict, "required_by"); reqby = prop_dictionary_get(dict, "required_by");
if (reqby && prop_array_count(reqby) > 0) if (reqby && prop_array_count(reqby) > 0)
sdep->reqby = prop_array_copy(reqby); sdep->reqby = prop_array_copy(reqby);
TAILQ_INSERT_TAIL(&sdep_list, sdep, chain); SIMPLEQ_INSERT_TAIL(&sdep_list, sdep, chain);
prop_array_remove(unsorted, curidx); prop_array_remove(unsorted, curidx);
maxprio = 0; maxprio = 0;
cnt++; cnt++;
@ -234,7 +234,7 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
* Pass 3: increase priority of dependencies any time * Pass 3: increase priority of dependencies any time
* a package requires them. * a package requires them.
*/ */
TAILQ_FOREACH(sdep, &sdep_list, chain) { SIMPLEQ_FOREACH(sdep, &sdep_list, chain) {
prop_dictionary_get_cstring_nocopy(sdep->dict, prop_dictionary_get_cstring_nocopy(sdep->dict,
"pkgname", &curpkg); "pkgname", &curpkg);
rundeps_array = prop_dictionary_get(sdep->dict, "run_depends"); rundeps_array = prop_dictionary_get(sdep->dict, "run_depends");
@ -275,7 +275,7 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
* Pass 4: increase priority of a package, by looking at * Pass 4: increase priority of a package, by looking at
* its required_by array member's priority. * its required_by array member's priority.
*/ */
TAILQ_FOREACH(sdep, &sdep_list, chain) { SIMPLEQ_FOREACH(sdep, &sdep_list, chain) {
iter = prop_array_iterator(sdep->reqby); iter = prop_array_iterator(sdep->reqby);
if (iter == NULL) if (iter == NULL)
continue; continue;
@ -301,7 +301,7 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
*/ */
while ((sdep = find_sorteddep_with_highest_prio()) != NULL) { while ((sdep = find_sorteddep_with_highest_prio()) != NULL) {
prop_array_add(sorted, sdep->dict); prop_array_add(sorted, sdep->dict);
TAILQ_REMOVE(&sdep_list, sdep, chain); SIMPLEQ_REMOVE(&sdep_list, sdep, sorted_dependency, chain);
prop_object_release(sdep->dict); prop_object_release(sdep->dict);
prop_object_release(sdep->reqby); prop_object_release(sdep->reqby);
free(sdep); free(sdep);
@ -324,8 +324,8 @@ out:
* Release resources used by temporary sorting. * Release resources used by temporary sorting.
*/ */
prop_object_release(sorted); prop_object_release(sorted);
while ((sdep = TAILQ_FIRST(&sdep_list)) != NULL) { while ((sdep = SIMPLEQ_FIRST(&sdep_list)) != NULL) {
TAILQ_REMOVE(&sdep_list, sdep, chain); SIMPLEQ_REMOVE(&sdep_list, sdep, sorted_dependency, chain);
prop_object_release(sdep->dict); prop_object_release(sdep->dict);
prop_object_release(sdep->reqby); prop_object_release(sdep->reqby);
free(sdep); free(sdep);