cache: clear the cache with pkgconf_cache_remove

Which results in more code re-use.
pull/239/head
Dylan Baker 2022-08-03 16:27:42 -07:00
parent e4d1c8ffa5
commit 171738024e
1 changed files with 4 additions and 36 deletions

View File

@ -174,7 +174,9 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
if (slot == NULL)
return;
(*slot)->flags &= ~PKGCONF_PKG_PROPF_CACHED;
pkgconf_pkg_unref(client, *slot);
*slot = NULL;
qsort(client->cache_table, client->cache_count,
@ -201,18 +203,6 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
}
}
static inline void
clear_dependency_matches(pkgconf_list_t *list)
{
pkgconf_node_t *iter;
PKGCONF_FOREACH_LIST_ENTRY(list->head, iter)
{
pkgconf_dependency_t *dep = iter->data;
dep->match = NULL;
}
}
/*
* !doc
*
@ -230,31 +220,9 @@ pkgconf_cache_free(pkgconf_client_t *client)
if (client->cache_table == NULL)
return;
pkgconf_pkg_t **cache_table;
size_t i, count;
while (client->cache_count > 0)
pkgconf_cache_remove(client, client->cache_table[0]);
cache_table = pkgconf_reallocarray(NULL, client->cache_count, sizeof (void *));
memcpy(cache_table, client->cache_table,
client->cache_count * sizeof (void *));
/* first we clear cached match pointers */
for (i = 0, count = client->cache_count; i < count; i++)
{
pkgconf_pkg_t *pkg = cache_table[i];
clear_dependency_matches(&pkg->required);
clear_dependency_matches(&pkg->requires_private);
clear_dependency_matches(&pkg->provides);
clear_dependency_matches(&pkg->conflicts);
}
/* now forcibly free everything */
for (i = 0, count = client->cache_count; i < count; i++)
{
pkgconf_pkg_t *pkg = cache_table[i];
pkgconf_pkg_free(client, pkg);
}
free(cache_table);
free(client->cache_table);
client->cache_table = NULL;
client->cache_count = 0;