From 67cfc4ebadeaa45743b6af01872f9766fe0bfd6b Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 16 Dec 2013 08:49:33 +0100 Subject: [PATCH] rpool: switch "struct xbps_repo" to be part of the rpool simpleq. The previous internal "struct rpool" was an extra structure that can be avoided by just using "struct xbps_repo" directly. This makes rpool use (at least) 4KB less per repository and 1 extra allocation. --- include/xbps.h.in | 4 +++- lib/rpool.c | 58 ++++++++++++++++++++--------------------------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/include/xbps.h.in b/include/xbps.h.in index fb8cfb16..ef315b99 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -27,6 +27,7 @@ #ifndef _XBPS_API_H_ #define _XBPS_API_H_ +#include #include #include @@ -46,7 +47,7 @@ * * This header documents the full API for the XBPS Library. */ -#define XBPS_API_VERSION "20131118" +#define XBPS_API_VERSION "20131216" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -1110,6 +1111,7 @@ struct xbps_repo { /** * @private */ + SIMPLEQ_ENTRY(xbps_repo) entries; struct archive *ar; /** * @var xhp diff --git a/lib/rpool.c b/lib/rpool.c index a6e052b4..a3628238 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -33,12 +33,7 @@ #include "xbps_api_impl.h" -struct rpool { - SIMPLEQ_ENTRY(rpool) entries; - struct xbps_repo *repo; -}; - -static SIMPLEQ_HEAD(rpool_head, rpool) rpool_queue = +static SIMPLEQ_HEAD(rpool_head, xbps_repo) rpool_queue = SIMPLEQ_HEAD_INITIALIZER(rpool_queue); /** @@ -50,7 +45,7 @@ static SIMPLEQ_HEAD(rpool_head, rpool) rpool_queue = int HIDDEN xbps_rpool_init(struct xbps_handle *xhp) { - struct rpool *rp; + struct xbps_repo *repo; const char *repouri; bool foundrepo = false; int retval, rv = 0; @@ -61,27 +56,25 @@ xbps_rpool_init(struct xbps_handle *xhp) return 0; for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { - rp = malloc(sizeof(struct rpool)); - assert(rp); xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); - if ((rp->repo = xbps_repo_open(xhp, repouri)) == NULL) { - rp->repo = calloc(1, sizeof(struct xbps_repo)); - assert(rp->repo); - rp->repo->xhp = xhp; - rp->repo->uri = repouri; + if ((repo = xbps_repo_open(xhp, repouri)) == NULL) { + repo = calloc(1, sizeof(struct xbps_repo)); + assert(repo); + repo->xhp = xhp; + repo->uri = repouri; if (xbps_repository_is_remote(repouri)) - rp->repo->is_remote = true; + repo->is_remote = true; } - if (rp->repo->is_remote) { - if (!rp->repo->is_signed) { + if (repo->is_remote) { + if (!repo->is_signed) { /* ignore unsigned repositories */ - xbps_repo_invalidate(rp->repo); + xbps_repo_invalidate(repo); } else { /* * Check the repository index signature against * stored public key. */ - retval = xbps_repo_key_verify(rp->repo); + retval = xbps_repo_key_verify(repo); if (retval == 0) { /* signed, verified */ xbps_set_cb_state(xhp, XBPS_STATE_REPO_SIGVERIFIED, @@ -90,23 +83,23 @@ xbps_rpool_init(struct xbps_handle *xhp) /* signed, unverified */ xbps_set_cb_state(xhp, XBPS_STATE_REPO_SIGUNVERIFIED, 0, repouri, NULL); - xbps_repo_invalidate(rp->repo); + xbps_repo_invalidate(repo); } else { /* any error */ xbps_dbg_printf(xhp, "[rpool] %s: key_verify %s\n", repouri, strerror(retval)); - xbps_repo_invalidate(rp->repo); + xbps_repo_invalidate(repo); } } } /* * If repository has passed signature checks, add it to the pool. */ - SIMPLEQ_INSERT_TAIL(&rpool_queue, rp, entries); + SIMPLEQ_INSERT_TAIL(&rpool_queue, repo, entries); foundrepo = true; xbps_dbg_printf(xhp, "[rpool] `%s' registered (%s, %s).\n", - repouri, rp->repo->is_signed ? "signed" : "unsigned", - rp->repo->is_verified ? "verified" : "unverified"); + repouri, repo->is_signed ? "signed" : "unsigned", + repo->is_verified ? "verified" : "unverified"); } if (!foundrepo) { /* no repositories available, error out */ @@ -126,16 +119,15 @@ out: void HIDDEN xbps_rpool_release(struct xbps_handle *xhp) { - struct rpool *rp; + struct xbps_repo *repo; if (!xhp->rpool_initialized) return; - while ((rp = SIMPLEQ_FIRST(&rpool_queue))) { - SIMPLEQ_REMOVE(&rpool_queue, rp, rpool, entries); - xbps_repo_close(rp->repo); - free(rp->repo); - free(rp); + while ((repo = SIMPLEQ_FIRST(&rpool_queue))) { + SIMPLEQ_REMOVE(&rpool_queue, repo, xbps_repo, entries); + xbps_repo_close(repo); + free(repo); } xhp->rpool_initialized = false; xbps_dbg_printf(xhp, "[rpool] released ok.\n"); @@ -168,7 +160,7 @@ xbps_rpool_foreach(struct xbps_handle *xhp, int (*fn)(struct xbps_repo *, void *, bool *), void *arg) { - struct rpool *rp; + struct xbps_repo *repo; int rv = 0; bool done = false; @@ -183,8 +175,8 @@ xbps_rpool_foreach(struct xbps_handle *xhp, return rv; } /* Iterate over repository pool */ - SIMPLEQ_FOREACH(rp, &rpool_queue, entries) { - rv = (*fn)(rp->repo, arg, &done); + SIMPLEQ_FOREACH(repo, &rpool_queue, entries) { + rv = (*fn)(repo, arg, &done); if (rv != 0 || done) break; }