summaryrefslogtreecommitdiff
path: root/src/poolid.c
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2008-03-04 17:52:55 +0000
committerMichael Schroeder <mls@suse.de>2008-03-04 17:52:55 +0000
commitb53291befd7bfbb2b7079d99932ad99213199de7 (patch)
tree4410c3eea95c5f6d959baf2c0b4e065a3b471c19 /src/poolid.c
parent17ebf966ddc0e16369af78f30d5a13e2fb00c368 (diff)
downloadlibsolv-b53291befd7bfbb2b7079d99932ad99213199de7.tar.gz
libsolv-b53291befd7bfbb2b7079d99932ad99213199de7.tar.bz2
libsolv-b53291befd7bfbb2b7079d99932ad99213199de7.zip
- clean up tmp space management
- return location in tmp space - move solvable2str into solvable.c
Diffstat (limited to 'src/poolid.c')
-rw-r--r--src/poolid.c91
1 files changed, 37 insertions, 54 deletions
diff --git a/src/poolid.c b/src/poolid.c
index a08c183..d1e449e 100644
--- a/src/poolid.c
+++ b/src/poolid.c
@@ -183,74 +183,57 @@ id2evr(Pool *pool, Id id)
return "";
rd = GETRELDEP(pool, id);
if (ISRELDEP(rd->evr))
- return "REL";
+ return "(REL)";
return pool->ss.stringspace + pool->ss.strings[rd->evr];
}
-const char *
-dep2str(Pool *pool, Id id)
+static int
+dep2strlen(Pool *pool, Id id)
{
- Reldep *rd;
- const char *sr;
- char *s1, *s2;
- int n, l, ls1, ls2, lsr;
-
- if (!ISRELDEP(id))
- return pool->ss.stringspace + pool->ss.strings[id];
- rd = GETRELDEP(pool, id);
- n = pool->dep2strn;
+ int l = 0;
- sr = id2rel(pool, id);
- lsr = strlen(sr);
-
- s2 = (char *)dep2str(pool, rd->evr);
- pool->dep2strn = n;
- ls2 = strlen(s2);
-
- s1 = (char *)dep2str(pool, rd->name);
- pool->dep2strn = n;
- ls1 = strlen(s1);
-
- if (rd->flags == REL_NAMESPACE)
+ while (ISRELDEP(id))
{
- sr = "(";
- lsr = 1;
- ls2++;
+ Reldep *rd = GETRELDEP(pool, id);
+ l += dep2strlen(pool, rd->name) + strlen(id2rel(pool, id));
+ id = rd->evr;
}
+ return l + strlen(pool->ss.stringspace + pool->ss.strings[id]);
+}
- l = ls1 + ls2 + lsr;
- if (l + 1 > pool->dep2strlen[n])
+static void
+dep2strcpy(Pool *pool, char *p, Id id)
+{
+ while (ISRELDEP(id))
{
- if (s1 != pool->dep2strbuf[n])
- pool->dep2strbuf[n] = sat_realloc(pool->dep2strbuf[n], l + 32);
- else
+ Reldep *rd = GETRELDEP(pool, id);
+ dep2strcpy(pool, p, rd->name);
+ p += strlen(p);
+ if (rd->flags == REL_NAMESPACE)
{
- pool->dep2strbuf[n] = sat_realloc(pool->dep2strbuf[n], l + 32);
- s1 = pool->dep2strbuf[n];
+ *p++ = '(';
+ dep2strcpy(pool, p, rd->evr);
+ strcat(p, ")");
+ return;
}
- pool->dep2strlen[n] = l + 32;
- }
- if (s1 != pool->dep2strbuf[n])
- {
- strcpy(pool->dep2strbuf[n], s1);
- s1 = pool->dep2strbuf[n];
+ strcpy(p, id2rel(pool, id));
+ p += strlen(p);
+ id = rd->evr;
}
- strcpy(s1 + ls1, sr);
- pool->dep2strbuf[n] = s1 + ls1 + lsr;
- s2 = (char *)dep2str(pool, rd->evr);
- if (s2 != pool->dep2strbuf[n])
- strcpy(pool->dep2strbuf[n], s2);
- pool->dep2strbuf[n] = s1;
- if (rd->flags == REL_NAMESPACE)
- {
- s1[ls1 + ls2 + lsr - 1] = ')';
- s1[ls1 + ls2 + lsr] = 0;
- }
- pool->dep2strn = (n + 1) % DEP2STRBUF;
- return s1;
+ strcpy(p, pool->ss.stringspace + pool->ss.strings[id]);
}
-
+const char *
+dep2str(Pool *pool, Id id)
+{
+ char *p;
+ if (!ISRELDEP(id))
+ return pool->ss.stringspace + pool->ss.strings[id];
+ p = pool_alloctmpspace(pool, dep2strlen(pool, id));
+ dep2strcpy(pool, p, id);
+ return p;
+}
+
void
pool_shrink_strings(Pool *pool)
{