From: Jaroslav Mracek Date: Tue, 10 Apr 2018 10:47:18 +0000 (+0200) Subject: Add const for second variable X-Git-Tag: 0.6.35~49^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b88c70c712c45b49d9ee352306aa8f6725d3793;p=thirdparty%2Flibsolv.git Add const for second variable The second variable is used as a source for copy and it is not modified therefore it should be marked as s const. Then it is more easy to identify what is source and what is target and also it is clear that the source variable will be not modify by the function. Additionally it allows to use const map or queue to create a copy or other operations. --- diff --git a/src/bitmap.c b/src/bitmap.c index e004bf2f..4e8adbd3 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -32,18 +32,18 @@ map_free(Map *m) m->size = 0; } -/* copy constructor t <- s */ +/* copy constructor target <- source */ void -map_init_clone(Map *t, Map *s) +map_init_clone(Map *target, const Map *source) { - t->size = s->size; - if (s->size) + target->size = source->size; + if (source->size) { - t->map = solv_malloc(s->size); - memcpy(t->map, s->map, s->size); + target->map = solv_malloc(source->size); + memcpy(target->map, source->map, source->size); } else - t->map = 0; + target->map = 0; } /* grow a map */ @@ -61,7 +61,7 @@ map_grow(Map *m, int n) /* bitwise-ands maps t and s, stores the result in t. */ void -map_and(Map *t, Map *s) +map_and(Map *t, const Map *s) { unsigned char *ti, *si, *end; ti = t->map; @@ -73,7 +73,7 @@ map_and(Map *t, Map *s) /* bitwise-ors maps t and s, stores the result in t. */ void -map_or(Map *t, Map *s) +map_or(Map *t, const Map *s) { unsigned char *ti, *si, *end; if (t->size < s->size) @@ -87,7 +87,7 @@ map_or(Map *t, Map *s) /* remove all set bits in s from t. */ void -map_subtract(Map *t, Map *s) +map_subtract(Map *t, const Map *s) { unsigned char *ti, *si, *end; ti = t->map; diff --git a/src/bitmap.h b/src/bitmap.h index 0050a6a4..1e895904 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -37,12 +37,12 @@ typedef struct _Map { #define MAPCLR_AT(m, n) ((m)->map[(n) >> 3] = 0) extern void map_init(Map *m, int n); -extern void map_init_clone(Map *t, Map *s); +extern void map_init_clone(Map *target, const Map *source); extern void map_grow(Map *m, int n); extern void map_free(Map *m); -extern void map_and(Map *t, Map *s); -extern void map_or(Map *t, Map *s); -extern void map_subtract(Map *t, Map *s); +extern void map_and(Map *t, const Map *s); +extern void map_or(Map *t, const Map *s); +extern void map_subtract(Map *t, const Map *s); extern void map_invertall(Map *m); static inline void map_empty(Map *m) diff --git a/src/queue.c b/src/queue.c index ceb1062f..6d5e531d 100644 --- a/src/queue.c +++ b/src/queue.c @@ -36,21 +36,21 @@ queue_init(Queue *q) } void -queue_init_clone(Queue *t, Queue *s) +queue_init_clone(Queue *target, const Queue *source) { int extra_space; - if (!s->elements) + if (!source->elements) { - t->alloc = t->elements = 0; - t->count = t->left = 0; + target->alloc = target->elements = 0; + target->count = target->left = 0; return; } - extra_space = queue_extra_space(s->count); - t->alloc = t->elements = solv_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 = extra_space; + extra_space = queue_extra_space(source->count); + target->alloc = target->elements = solv_malloc2(source->count + extra_space, sizeof(Id)); + if (source->count) + memcpy(target->alloc, source->elements, source->count * sizeof(Id)); + target->count = source->count; + target->left = extra_space; } void @@ -168,7 +168,7 @@ queue_delete2(Queue *q, int pos) } void -queue_insertn(Queue *q, int pos, int n, Id *elements) +queue_insertn(Queue *q, int pos, int n, const Id *elements) { if (n <= 0) return; diff --git a/src/queue.h b/src/queue.h index 4785e67a..7e560352 100644 --- a/src/queue.h +++ b/src/queue.h @@ -109,12 +109,12 @@ queue_truncate(Queue *q, int n) extern void queue_init(Queue *q); extern void queue_init_buffer(Queue *q, Id *buf, int size); -extern void queue_init_clone(Queue *t, Queue *s); +extern void queue_init_clone(Queue *target, const Queue *source); extern void queue_free(Queue *q); extern void queue_insert(Queue *q, int pos, Id id); extern void queue_insert2(Queue *q, int pos, Id id1, Id id2); -extern void queue_insertn(Queue *q, int pos, int n, Id *elements); +extern void queue_insertn(Queue *q, int pos, int n, const Id *elements); extern void queue_delete(Queue *q, int pos); extern void queue_delete2(Queue *q, int pos); extern void queue_deleten(Queue *q, int pos, int n);