Skip to content

Commit

Permalink
Init the whatprovides of new ids to an empty list for lazy file provides
Browse files Browse the repository at this point in the history
Otherwise finding the provides will always search the file list.
  • Loading branch information
mlschroe committed Sep 25, 2024
1 parent 2150865 commit 081580d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/poolid.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
#include "poolid_private.h"
#include "util.h"

static inline void
grow_whatprovides(Pool *pool, Id id)
{
if ((id & WHATPROVIDES_BLOCK) == 0)
{
/* grow whatprovides array */
pool->whatprovides = solv_realloc(pool->whatprovides, (id + (WHATPROVIDES_BLOCK + 1)) * sizeof(Offset));
memset(pool->whatprovides + id, 0, (WHATPROVIDES_BLOCK + 1) * sizeof(Offset));
}
if (pool->addedfileprovides == 1)
pool->whatprovides[id] = 1;
}

/* intern string into pool, return id */

Expand All @@ -28,12 +40,8 @@ pool_str2id(Pool *pool, const char *str, int create)
{
int oldnstrings = pool->ss.nstrings;
Id id = stringpool_str2id(&pool->ss, str, create);
if (create && pool->whatprovides && oldnstrings != pool->ss.nstrings && (id & WHATPROVIDES_BLOCK) == 0)
{
/* grow whatprovides array */
pool->whatprovides = solv_realloc(pool->whatprovides, (id + (WHATPROVIDES_BLOCK + 1)) * sizeof(Offset));
memset(pool->whatprovides + id, 0, (WHATPROVIDES_BLOCK + 1) * sizeof(Offset));
}
if (create && pool->whatprovides && oldnstrings != pool->ss.nstrings)
grow_whatprovides(pool, id);
return id;
}

Expand All @@ -42,12 +50,8 @@ pool_strn2id(Pool *pool, const char *str, unsigned int len, int create)
{
int oldnstrings = pool->ss.nstrings;
Id id = stringpool_strn2id(&pool->ss, str, len, create);
if (create && pool->whatprovides && oldnstrings != pool->ss.nstrings && (id & WHATPROVIDES_BLOCK) == 0)
{
/* grow whatprovides array */
pool->whatprovides = solv_realloc(pool->whatprovides, (id + (WHATPROVIDES_BLOCK + 1)) * sizeof(Offset));
memset(pool->whatprovides + id, 0, (WHATPROVIDES_BLOCK + 1) * sizeof(Offset));
}
if (create && pool->whatprovides && oldnstrings != pool->ss.nstrings)
grow_whatprovides(pool, id);
return id;
}

Expand Down

0 comments on commit 081580d

Please sign in to comment.