From 2c9ab6a1f27539c510c3b296086ba8180d65c553 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 8 Dec 2013 08:07:10 +0100 Subject: [PATCH] xbps_pkgdb_get_pkg_metadata: avoid an extra function call. --- lib/pkgdb.c | 71 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/lib/pkgdb.c b/lib/pkgdb.c index c6114eb8..10146d8a 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -189,42 +189,6 @@ xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *vpkg) return xbps_find_virtualpkg_in_dict(xhp, xhp->pkgdb, vpkg); } -static xbps_dictionary_t -get_pkg_metadata(struct xbps_handle *xhp, xbps_dictionary_t pkgd) -{ - xbps_dictionary_t pkg_metad; - const char *pkgver; - char *pkgname, *plist; - - xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); - pkgname = xbps_pkg_name(pkgver); - assert(pkgname); - - if ((pkg_metad = xbps_dictionary_get(xhp->pkg_metad, pkgname)) != NULL) { - free(pkgname); - return pkg_metad; - } - plist = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname); - pkg_metad = xbps_dictionary_internalize_from_file(plist); - free(plist); - - if (pkg_metad == NULL) { - xbps_dbg_printf(xhp, "[pkgdb] cannot read %s metadata: %s\n", - pkgver, strerror(errno)); - free(pkgname); - return NULL; - } - - if (xhp->pkg_metad == NULL) - xhp->pkg_metad = xbps_dictionary_create(); - - xbps_dictionary_set(xhp->pkg_metad, pkgname, pkg_metad); - xbps_object_release(pkg_metad); - free(pkgname); - - return pkg_metad; -} - static void generate_full_revdeps_tree(struct xbps_handle *xhp) { @@ -302,11 +266,42 @@ xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg) xbps_dictionary_t xbps_pkgdb_get_pkg_metadata(struct xbps_handle *xhp, const char *pkg) { - xbps_dictionary_t pkgd; + xbps_dictionary_t pkgd, pkg_metad; + const char *pkgver; + char *pkgname, *plist; + + if (pkg == NULL) + return NULL; pkgd = xbps_pkgdb_get_pkg(xhp, pkg); if (pkgd == NULL) return NULL; - return get_pkg_metadata(xhp, pkgd); + xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); + pkgname = xbps_pkg_name(pkgver); + assert(pkgname); + + if ((pkg_metad = xbps_dictionary_get(xhp->pkg_metad, pkgname)) != NULL) { + free(pkgname); + return pkg_metad; + } + plist = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname); + pkg_metad = xbps_dictionary_internalize_from_file(plist); + free(plist); + + if (pkg_metad == NULL) { + xbps_dbg_printf(xhp, "[pkgdb] cannot read %s metadata: %s\n", + pkgver, strerror(errno)); + free(pkgname); + return NULL; + } + + if (xhp->pkg_metad == NULL) + xhp->pkg_metad = xbps_dictionary_create(); + + xbps_dictionary_set(xhp->pkg_metad, pkgname, pkg_metad); + xbps_object_release(pkg_metad); + free(pkgname); + + return pkg_metad; }