X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Fset.c;h=37852248527c43c659b9d16b9a60ba09ae5275c8;hb=40f56bdee6900292d63f0d3edd8ab020e99750d5;hp=8ddd09acc4f7ed8ddae43b961b6fc264325cd02f;hpb=974215da1a935f250766874d0f7a7ddfa34bc4ef;p=libfirm diff --git a/ir/adt/set.c b/ir/adt/set.c index 8ddd09acc..378522485 100644 --- a/ir/adt/set.c +++ b/ir/adt/set.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -43,9 +43,7 @@ TODO: Fix Esmond's ugly MixedCapsIdentifiers ;-> */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #ifdef PSET # define SET pset @@ -116,8 +114,7 @@ struct SET { #ifdef STATS -void -MANGLEP(stats) (SET *table) +void MANGLEP(stats) (SET *table) { int nfree = 0; #ifdef PSET @@ -128,8 +125,7 @@ MANGLEP(stats) (SET *table) table->naccess, table->ncollision, table->nkey, table->ndups, table->max_chain_len, nfree); } -static INLINE void -stat_chain_len (SET *table, int chain_len) +static inline void stat_chain_len(SET *table, int chain_len) { table->ncollision += chain_len; if (table->max_chain_len < chain_len) table->max_chain_len = chain_len; @@ -151,8 +147,7 @@ stat_chain_len (SET *table, int chain_len) const char *MANGLEP(tag); -void -MANGLEP(describe) (SET *table) +void MANGLEP(describe) (SET *table) { unsigned i, j, collide; Element *ptr; @@ -182,11 +177,10 @@ MANGLEP(describe) (SET *table) #endif /* !DEBUG */ -SET * -(PMANGLE(new)) (MANGLEP(cmp_fun) cmp, int nslots) +SET *(PMANGLE(new)) (MANGLEP(cmp_fun) cmp, int nslots) { int i; - SET *table = xmalloc(sizeof(*table)); + SET *table = XMALLOC(SET); if (nslots > SEGMENT_SIZE * DIRECTORY_SIZE) nslots = DIRECTORY_SIZE; @@ -208,10 +202,7 @@ SET * /* Make segments */ for (i = 0; i < nslots; ++i) { - table->dir[i] = (Segment *)obstack_alloc (&table->obst, - sizeof (Segment) * SEGMENT_SIZE); - - memset(table->dir[i], 0, sizeof (Segment) * SEGMENT_SIZE); + table->dir[i] = OALLOCNZ(&table->obst, Segment, SEGMENT_SIZE); table->nseg++; } @@ -226,8 +217,7 @@ SET * } -void -PMANGLE(del) (SET *table) +void PMANGLE(del) (SET *table) { #ifdef DEBUG MANGLEP(tag) = table->tag; @@ -236,8 +226,7 @@ PMANGLE(del) (SET *table) xfree (table); } -int -MANGLEP(count) (SET *table) +int MANGLEP(count) (SET *table) { return table->nkey; } @@ -246,8 +235,7 @@ MANGLEP(count) (SET *table) * do one iteration step, return 1 * if still data in the set, 0 else */ -static INLINE int -iter_step (SET *table) +static inline int iter_step(SET *table) { if (++table->iter_j >= SEGMENT_SIZE) { table->iter_j = 0; @@ -262,8 +250,7 @@ iter_step (SET *table) /* * finds the first entry in the table */ -void * -MANGLEP(first) (SET *table) +void * MANGLEP(first) (SET *table) { assert (!table->iter_tail); table->iter_i = 0; @@ -279,8 +266,7 @@ MANGLEP(first) (SET *table) /* * returns next entry in the table */ -void * -MANGLEP(next) (SET *table) +void *MANGLEP(next) (SET *table) { if (!table->iter_tail) return NULL; @@ -298,8 +284,7 @@ MANGLEP(next) (SET *table) return table->iter_tail->entry.dptr; } -void -MANGLEP(break) (SET *table) +void MANGLEP(break) (SET *table) { table->iter_tail = NULL; } @@ -307,8 +292,7 @@ MANGLEP(break) (SET *table) /* * limit the hash value */ -static INLINE unsigned -Hash (SET *table, unsigned h) +static inline unsigned Hash(SET *table, unsigned h) { unsigned address; address = h & (table->maxp - 1); /* h % table->maxp */ @@ -321,8 +305,7 @@ Hash (SET *table, unsigned h) * returns non-zero if the number of elements in * the set is greater then number of segments * MAX_LOAD_FACTOR */ -static INLINE int -loaded (SET *table) +static inline int loaded(SET *table) { return ( ++table->nkey > (table->nseg << SEGMENT_SIZE_SHIFT) * MAX_LOAD_FACTOR); @@ -336,8 +319,7 @@ loaded (SET *table) * after all segments were split, table->p is set to zero and * table->maxp is duplicated. */ -static void -expand_table (SET *table) +static void expand_table(SET *table) { unsigned NewAddress; int OldSegmentIndex, NewSegmentIndex; @@ -359,10 +341,7 @@ expand_table (SET *table) NewSegmentDir = NewAddress >> SEGMENT_SIZE_SHIFT; NewSegmentIndex = NewAddress & (SEGMENT_SIZE-1); if (NewSegmentIndex == 0) { - table->dir[NewSegmentDir] = - (Segment *)obstack_alloc (&table->obst, - sizeof(Segment) * SEGMENT_SIZE); - memset(table->dir[NewSegmentDir], 0, sizeof(Segment) * SEGMENT_SIZE); + table->dir[NewSegmentDir] = OALLOCNZ(&table->obst, Segment, SEGMENT_SIZE); table->nseg++; } NewSegment = table->dir[NewSegmentDir]; @@ -397,8 +376,7 @@ expand_table (SET *table) } -void * -MANGLE(_,_search) (SET *table, +void * MANGLE(_,_search) (SET *table, const void *key, #ifndef PSET size_t size, @@ -445,7 +423,7 @@ MANGLE(_,_search) (SET *table, q = table->free_list; table->free_list = table->free_list->chain; } else { - q = obstack_alloc (&table->obst, sizeof (Element)); + q = OALLOC(&table->obst, Element); } q->entry.dptr = (void *)key; #else @@ -483,8 +461,7 @@ int pset_default_ptr_cmp(const void *x, const void *y) return x != y; } -void * -pset_remove (SET *table, const void *key, unsigned hash) +void *pset_remove(SET *table, const void *key, unsigned hash) { unsigned h; Segment *CurrentSegment; @@ -537,15 +514,13 @@ pset_remove (SET *table, const void *key, unsigned hash) } -void * -(pset_find) (SET *se, const void *key, unsigned hash) +void *(pset_find) (SET *se, const void *key, unsigned hash) { return pset_find (se, key, hash); } -void * -(pset_insert) (SET *se, const void *key, unsigned hash) +void *(pset_insert) (SET *se, const void *key, unsigned hash) { return pset_insert (se, key, hash); } @@ -557,7 +532,8 @@ MANGLEP(entry) * return pset_hinsert (se, key, hash); } -void pset_insert_pset_ptr(pset *target, pset *src) { +void pset_insert_pset_ptr(pset *target, pset *src) +{ void *elt; for (elt = pset_first(src); elt; elt = pset_next(src)) { pset_insert_ptr(target, elt); @@ -566,22 +542,19 @@ void pset_insert_pset_ptr(pset *target, pset *src) { #else /* !PSET */ -void * -(set_find) (set *se, const void *key, size_t size, unsigned hash) +void *(set_find) (set *se, const void *key, size_t size, unsigned hash) { return set_find (se, key, size, hash); } -void * -(set_insert) (set *se, const void *key, size_t size, unsigned hash) +void *(set_insert) (set *se, const void *key, size_t size, unsigned hash) { return set_insert (se, key, size, hash); } -set_entry * -(set_hinsert) (set *se, const void *key, size_t size, unsigned hash) +set_entry *(set_hinsert) (set *se, const void *key, size_t size, unsigned hash) { return set_hinsert (se, key, size, hash); }