Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Create a "reentrant" manifest parser this gives a 10% boost of pkg update performances
Baptiste Daroussin committed 12 years ago
commit 27f058b22b7a20f6316104255f14a5d0a0068878
parent 10bf72b
3 files changed +60 -3
modified libpkg/pkg.h.in
@@ -82,6 +82,7 @@ struct pkg_config_value;
struct pkg_plugin;

struct pkg_manifest_key;
+
struct pkg_manifest_parser;

/**
 * The system-wide pkg(1) status: ie. is it a) installed or otherwise
@@ -801,9 +802,12 @@ int pkg_delannotation(struct pkg *pkg, const char *tag);
 */
int pkg_parse_manifest(struct pkg *pkg, char *buf, struct pkg_manifest_key *key);
int pkg_parse_manifest_file(struct pkg *pkg, FILE *f, struct pkg_manifest_key *key);
+
int pkg_parse_manifest_file_r(struct pkg *pkg, FILE *f, struct pkg_manifest_parser *p);
int pkg_load_manifest_file(struct pkg *pkg, const char *fpath, struct pkg_manifest_key *key);
int pkg_manifest_keys_new(struct pkg_manifest_key **k);
void pkg_manifest_keys_free(struct pkg_manifest_key *k);
+
int pkg_manifest_parser_new(struct pkg_manifest_parser **p);
+
void pkg_manifest_parser_free(struct pkg_manifest_parser *p);

#define PKG_MANIFEST_EMIT_COMPACT 0x1
#define PKG_MANIFEST_EMIT_NOFILES (0x1 << 1)
modified libpkg/pkg_manifest.c
@@ -127,6 +127,39 @@ struct pkg_manifest_key {
	UT_hash_handle hh;
};

+
struct pkg_manifest_parser {
+
	yaml_parser_t parser;
+
	struct pkg_manifest_key *keys;
+
};
+

+
int
+
pkg_manifest_parser_new(struct pkg_manifest_parser **p)
+
{
+
	if (*p != NULL) {
+
		yaml_parser_delete(&(*p)->parser);
+
		yaml_parser_initialize(&(*p)->parser);
+
		return (EPKG_OK);
+
	}
+
	*p = calloc(1, sizeof(struct pkg_manifest_parser));
+
	if (*p == NULL)
+
		return (EPKG_FATAL);
+

+
	pkg_manifest_keys_new(&(*p)->keys);
+
	yaml_parser_initialize(&(*p)->parser);
+

+
	return (EPKG_OK);
+
}
+

+
void
+
pkg_manifest_parser_free(struct pkg_manifest_parser *p)
+
{
+
	if (p == NULL)
+
		return;
+

+
	pkg_manifest_keys_free(p->keys);
+
	yaml_parser_delete(&p->parser);
+
}
+

int
pkg_manifest_keys_new(struct pkg_manifest_key **key)
{
@@ -823,6 +856,23 @@ pkg_parse_manifest(struct pkg *pkg, char *buf, struct pkg_manifest_key *keys)
}

int
+
pkg_parse_manifest_file_r(struct pkg *pkg, FILE *f, struct pkg_manifest_parser *p)
+
{
+
	int rc;
+

+
	assert(pkg != NULL);
+
	assert(f != NULL);
+
	assert(p != NULL);
+

+
	pkg_debug(2, "%s", "Parsing manifest from file");
+
	yaml_parser_set_input_file(&p->parser, f);
+

+
	rc = parse_manifest(pkg, p->keys, &p->parser);
+

+
	return (rc);
+
}
+

+
int
pkg_parse_manifest_file(struct pkg *pkg, FILE *f, struct pkg_manifest_key *keys)
{
	yaml_parser_t parser;
modified libpkg/update.c
@@ -367,7 +367,7 @@ pkg_update_full(const char *repofile, struct pkg_repo *repo, time_t *mtime)
static int
pkg_add_from_manifest(FILE *f, const char *origin, long offset,
		const char *manifest_digest, const char *local_arch, sqlite3 *sqlite,
-
		struct pkg_manifest_key *keys, struct pkg **p)
+
		struct pkg_manifest_parser **parser, struct pkg **p)
{
	int rc = EPKG_OK;
	struct pkg *pkg;
@@ -388,7 +388,8 @@ pkg_add_from_manifest(FILE *f, const char *origin, long offset,

	pkg = *p;

-
	rc = pkg_parse_manifest_file(pkg, f, keys);
+
	pkg_manifest_parser_new(parser);
+
	rc = pkg_parse_manifest_file_r(pkg, f, *parser);
	if (rc != EPKG_OK) {
		goto cleanup;
	}
@@ -458,6 +459,7 @@ pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
			*item, *tmp_item;
	const char *myarch;
	struct pkg_manifest_key *keys = NULL;
+
	struct pkg_manifest_parser *parser = NULL;
	size_t linecap = 0;
	ssize_t linelen;

@@ -555,13 +557,14 @@ pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
	HASH_ITER(hh, ladd, item, tmp_item) {
		if (rc == EPKG_OK) {
			rc = pkg_add_from_manifest(fmanifest, item->origin,
-
			        item->offset, item->digest, myarch, sqlite, keys, &pkg);
+
			        item->offset, item->digest, myarch, sqlite, &parser, &pkg);
		}
		free(item->origin);
		free(item->digest);
		HASH_DEL(ladd, item);
		free(item);
	}
+
	pkg_manifest_parser_free(parser);
	pkg_emit_incremental_update(updated, removed, added, processed);

cleanup: