From e1e59a9e7325923e98268b6dfce5ef2b1aa9def9 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Thu, 23 Jul 2009 11:58:29 +0200 Subject: [PATCH] - beautify --- examples/solv.c | 21 +++++++++++++++++---- src/poolid.c | 3 +-- src/strpool.c | 38 +++++++++++++++++--------------------- src/strpool.h | 10 ++++++---- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/examples/solv.c b/examples/solv.c index 5f93a00..051d547 100644 --- a/examples/solv.c +++ b/examples/solv.c @@ -2277,6 +2277,9 @@ rerunsolver: solv->allowarchchange = 1; solv->allowvendorchange = 1; } + if (mainmode == MODE_ERASE) + solv->allowuninstall = 1; /* don't nag */ + // queue_push2(&job, SOLVER_DISTUPGRADE, 3); solver_solve(solv, &job); if (!solv->problems.count) @@ -2343,7 +2346,7 @@ rerunsolver: printf("Transaction summary:\n\n"); solver_printtransaction(solv); -#if 1 +#ifndef FEDORA if (1) { DUChanges duc[4]; @@ -2355,10 +2358,11 @@ rerunsolver: duc[3].path = "/etc"; transaction_calc_duchanges(trans, duc, 4); for (i = 0; i < 4; i++) - printf("duchanges %s: %d K %d\n", duc[i].path, duc[i].kbytes, duc[i].files); - printf("install size change: %d K\n", transaction_calc_installsizechange(trans)); + printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files); } #endif + printf("install size change: %d K\n", transaction_calc_installsizechange(trans)); + printf("\n"); if (!yesno("OK to continue (y/n)? ")) { @@ -2372,7 +2376,16 @@ rerunsolver: if (newpkgs) { - printf("Downloading %d packages\n", newpkgs); + int downloadsize = 0; + for (i = 0; i < newpkgs; i++) + { + Solvable *s; + + p = checkq.elements[i]; + s = pool_id2solvable(pool, p); + downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0); + } + printf("Downloading %d packages, %d K\n", newpkgs, downloadsize); newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps)); for (i = 0; i < newpkgs; i++) { diff --git a/src/poolid.c b/src/poolid.c index 0503224..05ba9ea 100644 --- a/src/poolid.c +++ b/src/poolid.c @@ -283,8 +283,7 @@ pool_shrink_rels(Pool *pool) void pool_freeidhashes(Pool *pool) { - pool->ss.stringhashtbl = sat_free(pool->ss.stringhashtbl); - pool->ss.stringhashmask = 0; + stringpool_freehash(&pool->ss); pool->relhashtbl = sat_free(pool->relhashtbl); pool->relhashmask = 0; } diff --git a/src/strpool.c b/src/strpool.c index 77d66fd..d2c7a8a 100644 --- a/src/strpool.c +++ b/src/strpool.c @@ -47,6 +47,13 @@ stringpool_free(Stringpool *ss) } void +stringpool_freehash(Stringpool *ss) +{ + ss->stringhashtbl = sat_free(ss->stringhashtbl); + ss->stringhashmask = 0; +} + +void stringpool_init_empty(Stringpool *ss) { const char *emptystrs[] = { @@ -70,27 +77,25 @@ stringpool_clone(Stringpool *ss, Stringpool *from) } Id -stringpool_strn2id(Stringpool *ss, const char *str, unsigned len, int create) +stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create) { Hashval h; unsigned int hh; Hashmask hashmask; - int i, space_needed; + int i; Id id; Hashtable hashtbl; // check string if (!str) return STRID_NULL; - if (!*str) + if (!len) return STRID_EMPTY; hashmask = ss->stringhashmask; hashtbl = ss->stringhashtbl; // expand hashtable if needed - // - // if (ss->nstrings * 2 > hashmask) { sat_free(hashtbl); @@ -111,7 +116,6 @@ stringpool_strn2id(Stringpool *ss, const char *str, unsigned len, int create) } // compute hash and check for match - h = strnhash(str, len) & hashmask; hh = HASHCHAIN_START; while ((id = hashtbl[h]) != 0) // follow hash overflow chain @@ -130,20 +134,13 @@ stringpool_strn2id(Stringpool *ss, const char *str, unsigned len, int create) hashtbl[h] = id; ss->strings = sat_extend(ss->strings, id, 1, sizeof(Offset), STRING_BLOCK); - // 'pointer' into stringspace is Offset of next free pos: sstrings - ss->strings[id] = ss->sstrings; - - space_needed = len + 1; - // make room in string buffer - ss->stringspace = sat_extend(ss->stringspace, ss->sstrings, space_needed, 1, STRINGSPACE_BLOCK); - // copy new string into buffer - memcpy(ss->stringspace + ss->sstrings, str, space_needed - 1); - // add the sentinel, we can't rely on it being in the source string (in - // case the LEN is not really strlen(str)) - ss->stringspace[ss->sstrings + space_needed - 1] = 0; - // next free pos is behind new string - ss->sstrings += space_needed; + ss->strings[id] = ss->sstrings; /* we will append to the end */ + // append string to stringspace + ss->stringspace = sat_extend(ss->stringspace, ss->sstrings, len + 1, 1, STRINGSPACE_BLOCK); + memcpy(ss->stringspace + ss->sstrings, str, len); + ss->stringspace[ss->sstrings + len] = 0; + ss->sstrings += len + 1; return id; } @@ -154,8 +151,7 @@ stringpool_str2id(Stringpool *ss, const char *str, int create) return STRID_NULL; if (!*str) return STRID_EMPTY; - unsigned len = strlen(str); - return stringpool_strn2id(ss, str, len, create); + return stringpool_strn2id(ss, str, (unsigned int)strlen(str), create); } void diff --git a/src/strpool.h b/src/strpool.h index 59e269f..3845ced 100644 --- a/src/strpool.h +++ b/src/strpool.h @@ -28,14 +28,16 @@ void stringpool_init(Stringpool *ss, const char *strs[]); void stringpool_init_empty(Stringpool *ss); void stringpool_clone(Stringpool *ss, Stringpool *from); void stringpool_free(Stringpool *ss); +void stringpool_freehash(Stringpool *ss); -Id stringpool_str2id (Stringpool *ss, const char *str, int create); -Id stringpool_strn2id (Stringpool *ss, const char *str, unsigned int len, int create); -void stringpool_shrink (Stringpool *ss); +Id stringpool_str2id(Stringpool *ss, const char *str, int create); +Id stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create); + +void stringpool_shrink(Stringpool *ss); static inline const char * -stringpool_id2str (Stringpool *ss, Id id) +stringpool_id2str(Stringpool *ss, Id id) { return ss->stringspace + ss->strings[id]; } -- 2.7.4