Mailinglist Archive: zypp-commit (171 mails)

< Previous Next >
[zypp-commit] <sat-solver> master : - code cleanup
  • From: Michael Schroeder <mls@xxxxxxx>
  • Date: Mon, 15 Jun 2009 18:08:50 +0200
  • Message-id: <E1MGEk3-0001ON-6f@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit cedeb5bc8eef67646497a67c0658fa9c87b732a1
Author: Michael Schroeder <mls@xxxxxxx>
Date: Mon Jun 15 18:08:50 2009 +0200

- code cleanup
---
src/bitmap.c | 20 ++++++++++++++++--
src/bitmap.h | 1 +
src/queue.c | 55 ++++++++++++++++++++++++++++++++++------------------
src/rules.c | 2 +-
src/solver.c | 4 +-
src/transaction.c | 9 +++++--
6 files changed, 63 insertions(+), 28 deletions(-)

diff --git a/src/bitmap.c b/src/bitmap.c
index 200bb41..064fc4a 100644
--- a/src/bitmap.c
+++ b/src/bitmap.c
@@ -16,6 +16,7 @@
#include "bitmap.h"
#include "util.h"

+/* constructor */
void
map_init(Map *m, int n)
{
@@ -23,7 +24,7 @@ map_init(Map *m, int n)
m->map = n ? sat_calloc(m->size, 1) : 0;
}

-// free space allocated
+/* destructor */
void
map_free(Map *m)
{
@@ -31,7 +32,7 @@ map_free(Map *m)
m->size = 0;
}

-// copy t <- s
+/* copy constructor t <- s */
void
map_init_clone(Map *t, Map *s)
{
@@ -40,4 +41,17 @@ map_init_clone(Map *t, Map *s)
memcpy(t->map, s->map, t->size);
}

-// EOF
+/* grow a map */
+void
+map_grow(Map *m, int n)
+{
+ n = (n + 7) >> 3;
+ if (m->size < n)
+ {
+ m->map = sat_realloc(m->map, n);
+ memset(m->map + m->size, 0, n - m->size);
+ m->size = n;
+ }
+}
+
+/* EOF */
diff --git a/src/bitmap.h b/src/bitmap.h
index 2373910..d9994c6 100644
--- a/src/bitmap.h
+++ b/src/bitmap.h
@@ -33,6 +33,7 @@ map_empty(Map *m)

extern void map_init(Map *m, int n);
extern void map_init_clone(Map *t, Map *s);
+extern void map_grow(Map *m, int n);
extern void map_free(Map *m);

#endif /* SATSOLVER_BITMAP_H */
diff --git a/src/queue.c b/src/queue.c
index 38fd765..2f9f75a 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -17,6 +17,13 @@
#include "util.h"

void
+queue_init(Queue *q)
+{
+ q->alloc = q->elements = 0;
+ q->count = q->left = 0;
+}
+
+void
queue_init_clone(Queue *t, Queue *s)
{
t->alloc = t->elements = sat_malloc2(s->count + 8, sizeof(Id));
@@ -27,13 +34,6 @@ queue_init_clone(Queue *t, Queue *s)
}

void
-queue_init(Queue *q)
-{
- q->alloc = q->elements = 0;
- q->count = q->left = 0;
-}
-
-void
queue_init_buffer(Queue *q, Id *buf, int size)
{
q->alloc = 0;
@@ -54,27 +54,44 @@ queue_free(Queue *q)
void
queue_alloc_one(Queue *q)
{
- if (q->alloc && q->alloc != q->elements)
+ if (!q->alloc)
{
- memmove(q->alloc, q->elements, q->count * sizeof(Id));
- q->left += q->elements - q->alloc;
+ /* queue was created with queue_init_buf */
+ q->alloc = sat_malloc2(q->count + 8, sizeof(Id));
+ if (q->count)
+ memcpy(q->alloc, q->elements, q->count * sizeof(Id));
q->elements = q->alloc;
+ q->left = 8;
}
- else if (q->alloc)
+ else if (q->alloc != q->elements)
{
- q->elements = q->alloc = sat_realloc2(q->alloc, q->count + 8,
sizeof(Id));
- q->left += 8;
+ int l = q->elements - q->alloc;
+ if (q->count)
+ memmove(q->alloc, q->elements, q->count * sizeof(Id));
+ q->elements -= l;
+ q->left += l;
}
else
{
- q->alloc = sat_malloc2(q->count + 8, sizeof(Id));
- if (q->count)
- memcpy(q->alloc, q->elements, q->count * sizeof(Id));
- q->elements = q->alloc;
- q->left += 8;
+ q->elements = q->alloc = sat_realloc2(q->alloc, q->count + 8,
sizeof(Id));
+ q->left = 8;
}
}

+/* make room for an element in front of queue */
+void
+queue_alloc_one_head(Queue *q)
+{
+ int l;
+ if (!q->alloc || !q->left)
+ queue_alloc_one(q);
+ l = q->left > 8 ? 8 : q->left;
+ if (q->count);
+ memmove(q->elements + l, q->elements, q->count * sizeof(Id));
+ q->elements += l;
+ q->left -= l;
+}
+
void
queue_insert(Queue *q, int pos, Id id)
{
@@ -106,7 +123,7 @@ queue_insert2(Queue *q, int pos, Id id1, Id id2)
{
memmove(q->elements + pos + 2, q->elements + pos, (q->count - 2 - pos) *
sizeof(Id));
q->elements[pos] = id1;
- q->elements[pos] = id2;
+ q->elements[pos + 1] = id2;
}
}

diff --git a/src/rules.c b/src/rules.c
index 11f3301..d13dd12 100644
--- a/src/rules.c
+++ b/src/rules.c
@@ -1221,7 +1221,7 @@ solver_addduprules(Solver *solv, Map *addedmap)
if (solv->installed && ps->repo == solv->installed)
{
if (!solv->updatemap.size)
- map_init(&solv->updatemap, pool->nsolvables);
+ map_grow(&solv->updatemap, pool->nsolvables);
MAPSET(&solv->updatemap, p);
if (!MAPTST(&solv->dupmap, p))
{
diff --git a/src/solver.c b/src/solver.c
index 055ea32..fccee4a 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -2357,7 +2357,7 @@ solver_calculate_noobsmap(Pool *pool, Map *noobsmap,
Queue *job)
what = job->elements[i + 1];
select = how & SOLVER_SELECTMASK;
if (!noobsmap->size)
- map_init(noobsmap, pool->nsolvables);
+ map_grow(noobsmap, pool->nsolvables);
FOR_JOB_SELECT(p, pp, select, what)
MAPSET(noobsmap, p);
}
@@ -2698,7 +2698,7 @@ solver_solve(Solver *solv, Queue *job)
if (!solv->installed || s->repo != solv->installed)
continue;
if (!solv->updatemap.size)
- map_init(&solv->updatemap, pool->nsolvables);
+ map_grow(&solv->updatemap, pool->nsolvables);
MAPSET(&solv->updatemap, p);
}
break;
diff --git a/src/transaction.c b/src/transaction.c
index 1e94df4..3d28be7 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -210,6 +210,9 @@ transaction_type(Transaction *trans, Id p, int mode)

type = transaction_base_type(trans, p);

+ if (type == SOLVER_TRANSACTION_IGNORE)
+ return SOLVER_TRANSACTION_IGNORE; /* not part of the transaction */
+
if ((mode & SOLVER_TRANSACTION_RPM_ONLY) != 0)
{
/* application wants to know what to feed to rpm */
@@ -454,7 +457,7 @@ transaction_classify(Transaction *trans, int mode, Queue
*classes)
}
}
/* now sort all vendor/arch changes */
- if (classes->count)
+ if (classes->count > 4)
sat_sort(classes->elements, classes->count / 4, 4 * sizeof(Id),
classify_cmp, trans);
/* finally add all classes. put erases last */
i = SOLVER_TRANSACTION_ERASE;
@@ -519,7 +522,7 @@ transaction_classify_pkgs(Transaction *trans, int mode, Id
class, Id from, Id to
continue;
}
}
- if (pkgs->count)
+ if (pkgs->count > 1)
sat_sort(pkgs->elements, pkgs->count, sizeof(Id), classify_cmp_pkgs,
trans);
}

@@ -543,7 +546,7 @@ create_transaction_info(Transaction *trans, Queue
*decisionq)
if (p <= 0 || p == SYSTEMSOLVABLE)
continue;
s = pool->solvables + p;
- if (s->repo == installed)
+ if (!s->repo || s->repo == installed)
continue;
noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
FOR_PROVIDES(p2, pp2, s->name)
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages