summaryrefslogtreecommitdiffhomepage
path: root/ir/adt
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-09-07 09:27:33 +0200
committerMatthias Braun <matze@braunis.de>2015-09-07 19:58:31 +0200
commitaaa4256491cad0c06fbd12fe26da1877870867d5 (patch)
tree47dfe3819dcc738e263c1da5081204eef03bf81b /ir/adt
parentdfebb000f609810ce38687e4c5ed832221bc51ae (diff)
array: Cleanup
Diffstat (limited to 'ir/adt')
-rw-r--r--ir/adt/array.c68
1 files changed, 29 insertions, 39 deletions
diff --git a/ir/adt/array.c b/ir/adt/array.c
index ac1bc8d..490509e 100644
--- a/ir/adt/array.c
+++ b/ir/adt/array.c
@@ -18,14 +18,6 @@
#define ARR_D_MAGIC FOURCC('A','R','R','D')
#define ARR_F_MAGIC FOURCC('A','R','R','F')
-#ifdef NDEBUG
-# define ARR_SET_DBGINF(descr, co) \
- ((void)(descr), (void)(co), (void)0)
-#else
-# define ARR_SET_DBGINF(descr, co) \
- ((descr)->magic = (co))
-#endif
-
/**
* An empty dynamic array descriptor.
*/
@@ -34,7 +26,7 @@ ir_arr_descr arr_mt_descr = { ARR_D_MAGIC, 0, 0, { { 0 } } };
void ir_verify_arr(const void *arr)
{
#ifndef NDEBUG
- ir_arr_descr *descr = ARR_DESCR(arr);
+ ir_arr_descr *const descr = ARR_DESCR(arr);
assert(descr->magic == ARR_D_MAGIC || descr->magic == ARR_F_MAGIC);
assert(descr->allocated >= descr->nelts);
#else
@@ -44,68 +36,65 @@ void ir_verify_arr(const void *arr)
void *ir_new_arr_d(struct obstack *obstack, size_t nelts, size_t elts_size)
{
- ir_arr_descr *dp;
-
- assert(obstack);
-
- dp = (ir_arr_descr*)obstack_alloc(obstack, ARR_ELTS_OFFS + elts_size);
- ARR_SET_DBGINF(dp, ARR_D_MAGIC);
+ ir_arr_descr *const dp
+ = (ir_arr_descr*)obstack_alloc(obstack, sizeof(*dp) + elts_size);
+#ifndef NDEBUG
+ dp->magic = ARR_D_MAGIC;
+#endif
dp->allocated = dp->nelts = nelts;
return dp->elts;
}
void *ir_new_arr_f(size_t nelts, size_t elts_size)
{
- ir_arr_descr *newa;
-
- newa = (ir_arr_descr*)xmalloc(ARR_ELTS_OFFS+elts_size);
- ARR_SET_DBGINF(newa, ARR_F_MAGIC);
- newa->allocated = newa->nelts = nelts;
- return newa->elts;
+ ir_arr_descr *const dp = (ir_arr_descr*)xmalloc(sizeof(*dp)+elts_size);
+#ifndef NDEBUG
+ dp->magic = ARR_F_MAGIC;
+#endif
+ dp->allocated = dp->nelts = nelts;
+ return dp->elts;
}
-void ir_del_arr_f(void *elts)
+void DEL_ARR_F(void *elts)
{
- ir_arr_descr *dp = ARR_DESCR (elts);
+ ir_verify_arr(elts);
- ARR_VRFY(elts);
+ ir_arr_descr *const dp = ARR_DESCR(elts);
assert(dp->magic == ARR_F_MAGIC);
-
#ifndef NDEBUG
dp->magic = 0xdeadbeef;
#endif
free(dp);
}
-void *ir_arr_setlen (void *elts, size_t nelts, size_t elts_size)
+void *ir_arr_setlen(void *elts, size_t nelts, size_t elts_size)
{
- ir_arr_descr *dp = ARR_DESCR (elts);
+ ir_verify_arr(elts);
+ ir_arr_descr *dp = ARR_DESCR(elts);
assert(dp->magic == ARR_F_MAGIC);
- ARR_VRFY(elts);
-
- dp = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+elts_size);
+ dp = (ir_arr_descr*)xrealloc(dp, sizeof(*dp)+elts_size);
dp->allocated = dp->nelts = nelts;
-
return dp->elts;
}
void *ir_arr_resize(void *elts, size_t nelts, size_t eltsize)
{
- ir_arr_descr *dp = ARR_DESCR(elts);
- size_t n;
+ ir_verify_arr(elts);
+ ir_arr_descr *dp = ARR_DESCR(elts);
assert(dp->magic == ARR_F_MAGIC);
- ARR_VRFY(elts);
/* @@@ lots of resizes for small nelts */
- n = MAX(1, dp->allocated);
- while (nelts > n) n <<= 1;
- while (3*nelts < n) n >>= 1;
+ size_t n = MAX(1, dp->allocated);
+ while (nelts > n)
+ n <<= 1;
+ while (3*nelts < n)
+ n >>= 1;
assert(n >= nelts);
if (n != dp->allocated) {
- dp = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+eltsize*n);
+ dp = (ir_arr_descr*)xrealloc(dp, sizeof(*dp) + eltsize*n);
dp->allocated = n;
}
dp->nelts = nelts;
@@ -135,8 +124,9 @@ size_t array_len(const void *arr)
*/
ir_arr_descr *array_descr(const void *arr)
{
- if (! arr)
+ if (arr == NULL)
return NULL;
return ARR_DESCR(arr);
}
+
#endif /* DEBUG_libfirm */