summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2011-03-24 18:39:46 +0100
committerMichael Schroeder <mls@suse.de>2011-03-24 18:39:46 +0100
commit89331e25f8970a00c380c71f57a3cfcea14017a6 (patch)
tree2e4b3a018daa57732e73e88c748853f8b63267c5 /src
parentee8b702323e57f70eb32bca8045b436600bbc60b (diff)
downloadlibsolv-89331e25f8970a00c380c71f57a3cfcea14017a6.tar.gz
libsolv-89331e25f8970a00c380c71f57a3cfcea14017a6.tar.bz2
libsolv-89331e25f8970a00c380c71f57a3cfcea14017a6.zip
- simplify schema2id hash handling, put repodata_free_schemahash in header file
Diffstat (limited to 'src')
-rw-r--r--src/repodata.c14
-rw-r--r--src/repodata.h3
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)
{