libxbps: use memcpy in critical paths for performance, fixed some memleaks.

This commit is contained in:
Juan RP 2012-06-18 10:43:05 +02:00
parent 3e93d235ff
commit c24ce8e4da
6 changed files with 28 additions and 27 deletions

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20120616" #define XBPS_API_VERSION "20120618"
#define XBPS_VERSION "0.16" #define XBPS_VERSION "0.16"
/** /**

View File

@ -222,9 +222,7 @@ xbps_end(struct xbps_handle *xhp)
xbps_rpool_release(xhp); xbps_rpool_release(xhp);
xbps_fetch_unset_cache_connection(); xbps_fetch_unset_cache_connection();
if (xhp->cfg != NULL)
cfg_free(xhp->cfg); cfg_free(xhp->cfg);
free(xhp->cachedir_priv); free(xhp->cachedir_priv);
free(xhp->metadir_priv); free(xhp->metadir_priv);
free(xhp->un_machine); free(xhp->un_machine);

View File

@ -81,8 +81,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
/* /*
* Register repository into the array. * Register repository into the array.
*/ */
d = prop_dictionary_create(); if ((d = prop_dictionary_create()) == NULL) {
if (d == NULL) {
rv = ENOMEM; rv = ENOMEM;
prop_object_release(array); prop_object_release(array);
goto out; goto out;
@ -93,11 +92,13 @@ xbps_rpool_init(struct xbps_handle *xhp)
prop_object_release(d); prop_object_release(d);
goto out; goto out;
} }
if (!xbps_add_obj_to_dict(d, array, "index")) { if (!prop_dictionary_set(d, "index", array)) {
rv = EINVAL; rv = EINVAL;
prop_object_release(array);
prop_object_release(d); prop_object_release(d);
goto out; goto out;
} }
prop_object_release(array);
if (!prop_array_add(xhp->repo_pool, d)) { if (!prop_array_add(xhp->repo_pool, d)) {
rv = EINVAL; rv = EINVAL;
prop_object_release(d); prop_object_release(d);
@ -124,7 +125,6 @@ out:
void HIDDEN void HIDDEN
xbps_rpool_release(struct xbps_handle *xhp) xbps_rpool_release(struct xbps_handle *xhp)
{ {
prop_array_t idx;
prop_dictionary_t d; prop_dictionary_t d;
size_t i; size_t i;
const char *uri; const char *uri;
@ -134,15 +134,14 @@ xbps_rpool_release(struct xbps_handle *xhp)
for (i = 0; i < prop_array_count(xhp->repo_pool); i++) { for (i = 0; i < prop_array_count(xhp->repo_pool); i++) {
d = prop_array_get(xhp->repo_pool, i); d = prop_array_get(xhp->repo_pool, i);
idx = prop_dictionary_get(d, "index");
if (xhp->flags & XBPS_FLAG_DEBUG) { if (xhp->flags & XBPS_FLAG_DEBUG) {
prop_dictionary_get_cstring_nocopy(d, "uri", &uri); prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
xbps_dbg_printf(xhp, "[rpool] unregistered " xbps_dbg_printf(xhp, "[rpool] unregistered "
"repository '%s'\n", uri); "repository '%s'\n", uri);
} }
prop_object_release(idx);
prop_object_release(d); prop_object_release(d);
} }
prop_object_release(xhp->repo_pool);
xhp->repo_pool = NULL; xhp->repo_pool = NULL;
xbps_dbg_printf(xhp, "[rpool] released ok.\n"); xbps_dbg_printf(xhp, "[rpool] released ok.\n");
} }

View File

@ -64,7 +64,8 @@ repo_find_virtualpkg_cb(struct xbps_handle *xhp,
rpf->pattern); rpf->pattern);
} }
if (rpf->pkgd) { if (rpf->pkgd) {
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring_nocopy(rpf->pkgd,
"repository", rpi->uri);
*done = true; *done = true;
return 0; return 0;
} }
@ -90,7 +91,8 @@ repo_find_virtualpkg_conf_cb(struct xbps_handle *xhp,
rpi->repo, rpf->pattern); rpi->repo, rpf->pattern);
} }
if (rpf->pkgd) { if (rpf->pkgd) {
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring_nocopy(rpf->pkgd,
"repository", rpi->uri);
*done = true; *done = true;
return 0; return 0;
} }
@ -126,7 +128,8 @@ repo_find_pkg_cb(struct xbps_handle *xhp,
* Package dictionary found, add the "repository" * Package dictionary found, add the "repository"
* object with the URI. * object with the URI.
*/ */
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring_nocopy(rpf->pkgd,
"repository", rpi->uri);
*done = true; *done = true;
return 0; return 0;
} }
@ -170,7 +173,8 @@ repo_find_best_pkg_cb(struct xbps_handle *xhp,
"[rpool] Found best match '%s' (%s).\n", "[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri); repopkgver, rpi->uri);
rpf->pkgd = pkgd; rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring_nocopy(rpf->pkgd,
"repository", rpi->uri);
rpf->bestpkgver = repopkgver; rpf->bestpkgver = repopkgver;
return 0; return 0;
} }
@ -183,7 +187,8 @@ repo_find_best_pkg_cb(struct xbps_handle *xhp,
"[rpool] Found best match '%s' (%s).\n", "[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri); repopkgver, rpi->uri);
rpf->pkgd = pkgd; rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri); prop_dictionary_set_cstring_nocopy(rpf->pkgd,
"repository", rpi->uri);
rpf->bestpkgver = repopkgver; rpf->bestpkgver = repopkgver;
} }
return 0; return 0;
@ -250,7 +255,7 @@ repo_find_pkg(struct xbps_handle *xhp,
return NULL; return NULL;
} }
return prop_dictionary_copy(rpf.pkgd); return rpf.pkgd;
} }
prop_dictionary_t prop_dictionary_t

View File

@ -111,9 +111,6 @@ pkgdep_find_idx(const char *name, const char *trans)
static void static void
pkgdep_release(struct pkgdep *pd) pkgdep_release(struct pkgdep *pd)
{ {
if (pd->d != NULL)
prop_object_release(pd->d);
free(pd->name); free(pd->name);
free(pd); free(pd);
pd = NULL; pd = NULL;
@ -133,12 +130,9 @@ pkgdep_alloc(prop_dictionary_t d, const char *name, const char *trans)
free(pd); free(pd);
return NULL; return NULL;
} }
if (d != NULL) pd->d = d;
pd->d = prop_dictionary_copy(d); memcpy(pd->name, name, len-1);
else pd->name[len-1] = '\0';
pd->d = NULL;
(void)strlcpy(pd->name, name, len);
pd->trans = trans; pd->trans = trans;
return pd; return pd;
@ -318,6 +312,7 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps"); unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (prop_array_count(unsorted) == 0) { if (prop_array_count(unsorted) == 0) {
prop_dictionary_set(xhp->transd, "packages", sorted); prop_dictionary_set(xhp->transd, "packages", sorted);
prop_object_release(sorted);
return 0; return 0;
} }
/* /*

View File

@ -150,7 +150,9 @@ xbps_pkg_name(const char *pkg)
len = strlen(pkg) - strlen(p) + 1; len = strlen(pkg) - strlen(p) + 1;
buf = malloc(len); buf = malloc(len);
assert(buf != NULL); assert(buf != NULL);
strlcpy(buf, pkg, len);
memcpy(buf, pkg, len-1);
buf[len-1] = '\0';
return buf; return buf;
} }
@ -172,7 +174,9 @@ xbps_pkgpattern_name(const char *pkg)
pkgname = malloc(len); pkgname = malloc(len);
assert(pkgname != NULL); assert(pkgname != NULL);
strlcpy(pkgname, pkg, len);
memcpy(pkgname, pkg, len-1);
pkgname[len-1] = '\0';
return pkgname; return pkgname;
} }