From 89331e25f8970a00c380c71f57a3cfcea14017a6 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Thu, 24 Mar 2011 18:39:46 +0100 Subject: [PATCH] - simplify schema2id hash handling, put repodata_free_schemahash in header file --- src/repodata.c | 14 ++++++++------ src/repodata.h | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/repodata.c b/src/repodata.c index 8970d3d..df120ac 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -52,6 +52,7 @@ repodata_initdata(Repodata *data, Repo *repo, int localpool) data->localpool = localpool; if (localpool) stringpool_init_empty(&data->spool); + /* dirpool_init(&data->dirpool); just zeros out again */ data->keys = sat_calloc(1, sizeof(Repokey)); data->nkeys = 1; data->schemata = sat_calloc(1, sizeof(Id)); @@ -182,15 +183,17 @@ repodata_schema2id(Repodata *data, Id *schema, int create) Id *sp, cid; Id *schematahash; + if (!*schema) + return 0; /* XXX: allow empty schema? */ if ((schematahash = data->schematahash) == 0) { data->schematahash = schematahash = sat_calloc(256, sizeof(Id)); - for (i = 0; i < data->nschemata; i++) + for (i = 1; i < data->nschemata; i++) { for (sp = data->schemadata + data->schemata[i], h = 0; *sp; len++) h = h * 7 + *sp++; h &= 255; - schematahash[h] = i + 1; + schematahash[h] = i; } data->schemadata = sat_extend_resize(data->schemadata, data->schemadatalen, sizeof(Id), SCHEMATADATA_BLOCK); data->schemata = sat_extend_resize(data->schemata, data->nschemata, sizeof(Id), SCHEMATA_BLOCK); @@ -204,11 +207,10 @@ repodata_schema2id(Repodata *data, Id *schema, int create) cid = schematahash[h]; if (cid) { - cid--; if (!memcmp(data->schemadata + data->schemata[cid], schema, len * sizeof(Id))) return cid; - /* cache conflict */ - for (cid = 0; cid < data->nschemata; cid++) + /* cache conflict, do a slow search */ + for (cid = 1; cid < data->nschemata; cid++) if (!memcmp(data->schemadata + data->schemata[cid], schema, len * sizeof(Id))) return cid; } @@ -221,7 +223,7 @@ repodata_schema2id(Repodata *data, Id *schema, int create) memcpy(data->schemadata + data->schemadatalen, schema, len * sizeof(Id)); data->schemata[data->nschemata] = data->schemadatalen; data->schemadatalen += len; - schematahash[h] = data->nschemata + 1; + schematahash[h] = data->nschemata; #if 0 fprintf(stderr, "schema2id: new schema\n"); #endif diff --git a/src/repodata.h b/src/repodata.h index b0d9ea8..5746843 100644 --- a/src/repodata.h +++ b/src/repodata.h @@ -127,6 +127,7 @@ void repodata_empty(Repodata *data, int localpool); * key management functions */ Id repodata_key2id(Repodata *data, Repokey *key, int create); + static inline Repokey * repodata_id2key(Repodata *data, Id keyid) { @@ -137,6 +138,8 @@ repodata_id2key(Repodata *data, Id keyid) * schema management functions */ Id repodata_schema2id(Repodata *data, Id *schema, int create); +void repodata_free_schemahash(Repodata *data); + static inline Id * repodata_id2schema(Repodata *data, Id schemaid) { -- 2.7.4