diff --git a/libpkgconf/dependency.c b/libpkgconf/dependency.c index 1a4ec68..cd01a06 100644 --- a/libpkgconf/dependency.c +++ b/libpkgconf/dependency.c @@ -132,6 +132,9 @@ pkgconf_dependency_free(pkgconf_list_t *list) { pkgconf_dependency_t *dep = node->data; + if (dep->match != NULL) + pkgconf_pkg_unref(NULL, dep->match); + if (dep->package != NULL) free(dep->package); diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index 30f52a7..85d6ae2 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -87,6 +87,7 @@ struct pkgconf_dependency_ { pkgconf_pkg_comparator_t compare; char *version; pkgconf_pkg_t *parent; + pkgconf_pkg_t *match; }; struct pkgconf_tuple_ { diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index f883623..0e8c39f 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -1273,6 +1273,12 @@ pkgconf_pkg_verify_dependency(pkgconf_client_t *client, pkgconf_dependency_t *pk PKGCONF_TRACE(client, "trying to verify dependency: %s", pkgdep->package); + if (pkgdep->match != NULL) + { + PKGCONF_TRACE(client, "cached dependency: %s -> %s@%p", pkgdep->package, pkgdep->match->id, pkgdep->match); + return pkgconf_pkg_ref(client, pkgdep->match); + } + pkg = pkgconf_pkg_find(client, pkgdep->package); if (pkg == NULL) { @@ -1290,11 +1296,13 @@ pkgconf_pkg_verify_dependency(pkgconf_client_t *client, pkgconf_dependency_t *pk if (pkg->id == NULL) pkg->id = strdup(pkgdep->package); - if (pkgconf_pkg_comparator_impls[pkgdep->compare](pkg->version, pkgdep->version) == true) - return pkg; - - if (eflags != NULL) - *eflags |= PKGCONF_PKG_ERRF_PACKAGE_VER_MISMATCH; + if (pkgconf_pkg_comparator_impls[pkgdep->compare](pkg->version, pkgdep->version) != true) + { + if (eflags != NULL) + *eflags |= PKGCONF_PKG_ERRF_PACKAGE_VER_MISMATCH; + } + else + pkgdep->match = pkgconf_pkg_ref(client, pkg); return pkg; }