array: Remove the attribute eltsize from struct ir_arr_descr.
[libfirm] / ir / adt / array.c
index ed4fb5b..f934fa4 100644 (file)
@@ -21,7 +21,6 @@
  * @file
  * @brief       Array --- dynamic & flexible arrays.
  * @author      Markus Armbruster
- * @version     $Id$
  */
 
 #include "config.h"
@@ -47,7 +46,7 @@
 /**
  * An empty dynamic array descriptor.
  */
-ir_arr_descr arr_mt_descr = { ARR_D_MAGIC, 0, { 0 }, 0,  { { 0 } } };
+ir_arr_descr arr_mt_descr = { ARR_D_MAGIC, 0, 0, { { 0 } } };
 
 void ir_verify_arr(const void *arr)
 {
@@ -55,9 +54,7 @@ void ir_verify_arr(const void *arr)
        ir_arr_descr *descr = ARR_DESCR(arr);
        assert(descr->magic == ARR_D_MAGIC || descr->magic == ARR_A_MAGIC
                         || descr->magic == ARR_F_MAGIC);
-       if (descr->magic == ARR_F_MAGIC) {
-               assert(descr->u.allocated >= descr->nelts);
-       }
+       assert(descr->magic != ARR_F_MAGIC || descr->allocated >= descr->nelts);
 #else
        (void) arr;
 #endif
@@ -82,9 +79,8 @@ void *ir_new_arr_d(struct obstack *obstack, size_t nelts, size_t elts_size)
        assert(obstack);
 
        dp = (ir_arr_descr*)obstack_alloc(obstack, ARR_ELTS_OFFS + elts_size);
-       ARR_SET_DBGINF(dp, ARR_D_MAGIC, elts_size/nelts);
-       dp->u.obstack = obstack;
-       dp->nelts = nelts;
+       ARR_SET_DBGINF(dp, ARR_D_MAGIC);
+       dp->allocated = dp->nelts = nelts;
        return dp->elts;
 }
 
@@ -104,8 +100,8 @@ 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, nelts ? elts_size/nelts : 0);
-       newa->u.allocated = newa->nelts = nelts;
+       ARR_SET_DBGINF(newa, ARR_F_MAGIC);
+       newa->allocated = newa->nelts = nelts;
        return newa->elts;
 }
 
@@ -147,10 +143,9 @@ void *ir_arr_setlen (void *elts, size_t nelts, size_t elts_size)
 
        assert(dp->magic == ARR_F_MAGIC);
        ARR_VRFY(elts);
-       assert(!dp->eltsize || !nelts || (dp->eltsize == elts_size/nelts));
 
        dp = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+elts_size);
-       dp->u.allocated = dp->nelts = nelts;
+       dp->allocated = dp->nelts = nelts;
 
        return dp->elts;
 }
@@ -175,17 +170,16 @@ void *ir_arr_resize(void *elts, size_t nelts, size_t eltsize)
 
        assert(dp->magic == ARR_F_MAGIC);
        ARR_VRFY(elts);
-       assert(dp->eltsize ? dp->eltsize == eltsize : (dp->eltsize = eltsize, 1));
 
        /* @@@ lots of resizes for small nelts */
-       n = MAX(1, dp->u.allocated);
+       n = MAX(1, dp->allocated);
        while (nelts > n) n <<= 1;
        while (3*nelts < n) n >>= 1;
        assert(n >= nelts);
 
-       if (n != dp->u.allocated) {
+       if (n != dp->allocated) {
                dp = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+eltsize*n);
-               dp->u.allocated = n;
+               dp->allocated = n;
        }
        dp->nelts = nelts;