Implemented plist caching, that gives >30% performance.

--HG--
extra : convert_revision : 6302893f967be96f99a86d499ca62a8c005e56f7
This commit is contained in:
Juan RP
2009-05-19 01:42:48 +02:00
parent 55f2f51b40
commit 38e6679ff5
7 changed files with 100 additions and 93 deletions

View File

@@ -35,17 +35,15 @@
#include <xbps_api.h>
static prop_dictionary_t pkg_props;
static bool pkg_props_initialized;
static int
create_pkg_props_dictionary(void)
{
prop_array_t unsorted, missing;
int rv = 0;
static bool pkg_props_avail;
assert(pkgname != NULL);
if (pkg_props_avail)
if (pkg_props_initialized)
return 0;
pkg_props = prop_dictionary_create();
@@ -73,7 +71,7 @@ create_pkg_props_dictionary(void)
goto fail3;
}
pkg_props_avail = true;
pkg_props_initialized = true;
return rv;
@@ -90,7 +88,7 @@ fail:
prop_dictionary_t
xbps_get_pkg_props(void)
{
if (pkg_props == NULL || prop_dictionary_count(pkg_props) == 0)
if (pkg_props_initialized == false)
return NULL;
return prop_dictionary_copy(pkg_props);
@@ -107,18 +105,12 @@ xbps_prepare_repolist_data(void)
const char *rootdir;
char *plist;
int rv = 0;
static bool repodata_init;
static bool repodata_initialized;
if (repodata_init == false) {
SIMPLEQ_INIT(&repodata_queue);
repodata_init = true;
}
if (repodata_initialized)
return 0;
rdata = malloc(sizeof(struct repository_data));
if (rdata == NULL) {
rv = errno;
goto out;
}
SIMPLEQ_INIT(&repodata_queue);
rootdir = xbps_get_rootdir();
if (rootdir == NULL)
@@ -163,6 +155,12 @@ xbps_prepare_repolist_data(void)
goto out2;
}
rdata = malloc(sizeof(struct repository_data));
if (rdata == NULL) {
rv = errno;
goto out2;
}
rdata->rd_repod = prop_dictionary_internalize_from_file(plist);
if (rdata->rd_repod == NULL) {
free(plist);
@@ -173,6 +171,8 @@ xbps_prepare_repolist_data(void)
SIMPLEQ_INSERT_TAIL(&repodata_queue, rdata, chain);
}
repodata_initialized = true;
out2:
prop_object_iterator_release(iter);
out:

View File

@@ -34,6 +34,7 @@
#include <xbps_api.h>
static prop_dictionary_t regpkgdb_dict;
static bool regpkgdb_initialized;
bool
xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj,
@@ -162,16 +163,16 @@ xbps_find_pkg_from_plist(const char *plist, const char *pkgname)
prop_dictionary_t
xbps_find_pkg_installed_from_plist(const char *pkgname)
{
prop_dictionary_t instd, pkgd;
prop_dictionary_t pkgd;
instd = xbps_get_regpkgdb_dict();
if (instd == NULL)
if (regpkgdb_initialized == false)
return NULL;
pkgd = xbps_find_pkg_in_dict(instd, "packages", pkgname);
xbps_release_regpkgdb_dict();
pkgd = xbps_find_pkg_in_dict(regpkgdb_dict, "packages", pkgname);
if (pkgd == NULL)
return NULL;
return pkgd;
return prop_dictionary_copy(pkgd);
}
prop_dictionary_t
@@ -201,12 +202,12 @@ xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key,
}
prop_dictionary_t
xbps_get_regpkgdb_dict(void)
xbps_prepare_regpkgdb_dict(void)
{
const char *rootdir;
char *plist;
if (regpkgdb_dict == NULL) {
if (regpkgdb_initialized == false) {
rootdir = xbps_get_rootdir();
plist = xbps_xasprintf("%s/%s/%s", rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
@@ -219,6 +220,7 @@ xbps_get_regpkgdb_dict(void)
return NULL;
}
free(plist);
regpkgdb_initialized = true;
}
return prop_dictionary_copy(regpkgdb_dict);
@@ -227,11 +229,12 @@ xbps_get_regpkgdb_dict(void)
void
xbps_release_regpkgdb_dict(void)
{
if (regpkgdb_dict == NULL)
if (regpkgdb_initialized == false)
return;
prop_object_release(regpkgdb_dict);
regpkgdb_dict = NULL;
regpkgdb_initialized = false;
}
bool