summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2009-06-17 16:40:46 +0200
committerMichael Schroeder <mls@suse.de>2009-06-17 16:40:46 +0200
commit8c908fb220d569d5ac829c406c2f67658607460e (patch)
treef88d4649926a6691403a6334801efe1f09d3430e
parentdcfb57c9ac4e2e1c26674546080f000230add12c (diff)
downloadlibsolv-8c908fb220d569d5ac829c406c2f67658607460e.tar.gz
libsolv-8c908fb220d569d5ac829c406c2f67658607460e.tar.bz2
libsolv-8c908fb220d569d5ac829c406c2f67658607460e.zip
- beautify
-rw-r--r--src/bitmap.c11
-rw-r--r--src/queue.c28
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));