Mailinglist Archive: zypp-commit (171 mails)

< Previous Next >
[zypp-commit] <sat-solver> master : - beautify
  • From: Michael Schroeder <mls@xxxxxxx>
  • Date: Wed, 17 Jun 2009 16:40:46 +0200
  • Message-id: <E1MGwJs-0003f1-Iy@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 2589ce02d18e0fba3296fb0c9cf04cadb8403940
Author: Michael Schroeder <mls@xxxxxxx>
Date: Wed Jun 17 16:40:46 2009 +0200

- beautify
---
src/bitmap.c | 11 ++++++++---
src/queue.c | 28 ++++++++++++++++++----------
2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/bitmap.c b/src/bitmap.c
index 064fc4a..0485945 100644
--- a/src/bitmap.c
+++ b/src/bitmap.c
@@ -21,7 +21,7 @@ void
map_init(Map *m, int n)
{
m->size = (n + 7) >> 3;
- m->map = n ? sat_calloc(m->size, 1) : 0;
+ m->map = m->size ? sat_calloc(m->size, 1) : 0;
}

/* destructor */
@@ -37,8 +37,13 @@ void
map_init_clone(Map *t, Map *s)
{
t->size = s->size;
- t->map = sat_malloc(s->size);
- memcpy(t->map, s->map, t->size);
+ if (s->size)
+ {
+ t->map = sat_malloc(s->size);
+ memcpy(t->map, s->map, s->size);
+ }
+ else
+ t->map = 0;
}

/* grow a map */
diff --git a/src/queue.c b/src/queue.c
index fa10339..b2de746 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -16,6 +16,9 @@
#include "queue.h"
#include "util.h"

+#define EXTRA_SPACE 8
+#define EXTRA_SPACE_HEAD 8
+
void
queue_init(Queue *q)
{
@@ -26,11 +29,17 @@ queue_init(Queue *q)
void
queue_init_clone(Queue *t, Queue *s)
{
- t->alloc = t->elements = sat_malloc2(s->count + 8, sizeof(Id));
+ if (!s->elements)
+ {
+ t->alloc = t->elements = 0;
+ t->count = t->left = 0;
+ return;
+ }
+ t->alloc = t->elements = sat_malloc2(s->count + EXTRA_SPACE, sizeof(Id));
if (s->count)
memcpy(t->alloc, s->elements, s->count * sizeof(Id));
t->count = s->count;
- t->left = 8;
+ t->left = EXTRA_SPACE;
}

void
@@ -56,12 +65,11 @@ queue_alloc_one(Queue *q)
{
if (!q->alloc)
{
- /* queue was created with queue_init_buf */
- q->alloc = sat_malloc2(q->count + 8, sizeof(Id));
+ q->alloc = sat_malloc2(q->count + EXTRA_SPACE, sizeof(Id));
if (q->count)
memcpy(q->alloc, q->elements, q->count * sizeof(Id));
q->elements = q->alloc;
- q->left = 8;
+ q->left = EXTRA_SPACE;
}
else if (q->alloc != q->elements)
{
@@ -73,8 +81,8 @@ queue_alloc_one(Queue *q)
}
else
{
- q->elements = q->alloc = sat_realloc2(q->alloc, q->count + 8,
sizeof(Id));
- q->left = 8;
+ q->elements = q->alloc = sat_realloc2(q->alloc, q->count + EXTRA_SPACE,
sizeof(Id));
+ q->left = EXTRA_SPACE;
}
}

@@ -85,7 +93,7 @@ queue_alloc_one_head(Queue *q)
int l;
if (!q->alloc || !q->left)
queue_alloc_one(q);
- l = q->left > 8 ? 8 : q->left;
+ l = q->left > EXTRA_SPACE_HEAD ? EXTRA_SPACE_HEAD : q->left;
if (q->count);
memmove(q->elements + l, q->elements, q->count * sizeof(Id));
q->elements += l;
@@ -157,9 +165,9 @@ queue_insertn(Queue *q, int pos, int n)
if (!q->alloc)
queue_alloc_one(q);
off = q->elements - q->alloc;
- q->alloc = sat_realloc2(q->alloc, off + q->count + n + 8, sizeof(Id));
+ q->alloc = sat_realloc2(q->alloc, off + q->count + n + EXTRA_SPACE,
sizeof(Id));
q->elements = q->alloc + off;
- q->left = n + 8;
+ q->left = n + EXTRA_SPACE;
}
if (pos < q->count)
memmove(q->elements + pos + n, q->elements + pos, (q->count - pos) *
sizeof(Id));
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >