From d5566c6038845e505f7c16130b2368ef9bb3a373 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 15 Jan 2010 19:11:54 -0800 Subject: Remove struct keyword from all types, use typedef instead. --- src/upb_table.h | 84 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) (limited to 'src/upb_table.h') diff --git a/src/upb_table.h b/src/upb_table.h index f7f548b..122aed3 100644 --- a/src/upb_table.h +++ b/src/upb_table.h @@ -28,59 +28,57 @@ typedef uint32_t upb_inttable_key_t; #define UPB_END_OF_CHAIN (uint32_t)0 #define UPB_EMPTY_ENTRY (uint32_t)0 -struct upb_inttable_entry { +typedef struct { upb_inttable_key_t key; uint32_t next; /* Internal chaining. */ -}; +} upb_inttable_entry; // TODO: consider storing the hash in the entry. This would avoid the need to // rehash on table resizes, but more importantly could possibly improve lookup // performance by letting us compare hashes before comparing lengths or the // strings themselves. -struct upb_strtable_entry { +typedef struct { upb_strptr key; // We own a frozen ref. uint32_t next; // Internal chaining. -}; +} upb_strtable_entry; -struct upb_table { +typedef struct { void *entries; uint32_t count; /* How many elements are currently in the table? */ uint16_t entry_size; /* How big is each entry? */ uint8_t size_lg2; /* The table is 2^size_lg2 in size. */ uint32_t mask; -}; +} upb_table; -struct upb_strtable { - struct upb_table t; -}; +typedef struct { + upb_table t; +} upb_strtable; -struct upb_inttable { - struct upb_table t; -}; +typedef struct { + upb_table t; +} upb_inttable; /* Initialize and free a table, respectively. Specify the initial size * with 'size' (the size will be increased as necessary). Entry size * specifies how many bytes each entry in the table is. */ -void upb_inttable_init(struct upb_inttable *table, - uint32_t size, uint16_t entry_size); -void upb_inttable_free(struct upb_inttable *table); -void upb_strtable_init(struct upb_strtable *table, - uint32_t size, uint16_t entry_size); -void upb_strtable_free(struct upb_strtable *table); - -INLINE uint32_t upb_table_size(struct upb_table *t) { return 1 << t->size_lg2; } -INLINE uint32_t upb_inttable_size(struct upb_inttable *t) { +void upb_inttable_init(upb_inttable *table, uint32_t size, uint16_t entry_size); +void upb_inttable_free(upb_inttable *table); +void upb_strtable_init(upb_strtable *table, uint32_t size, uint16_t entry_size); +void upb_strtable_free(upb_strtable *table); + +INLINE uint32_t upb_table_size(upb_table *t) { return 1 << t->size_lg2; } +INLINE uint32_t upb_inttable_size(upb_inttable *t) { return upb_table_size(&t->t); } -INLINE uint32_t upb_strtable_size(struct upb_strtable *t) { +INLINE uint32_t upb_strtable_size(upb_strtable *t) { return upb_table_size(&t->t); } -INLINE uint32_t upb_table_count(struct upb_table *t) { return t->count; } -INLINE uint32_t upb_inttable_count(struct upb_inttable *t) { +INLINE uint32_t upb_table_count(upb_table *t) { return t->count; } +INLINE uint32_t upb_inttable_count(upb_inttable *t) { return upb_table_count(&t->t); } -INLINE uint32_t upb_strtable_count(struct upb_strtable *t) { +INLINE uint32_t upb_strtable_count(upb_strtable *t) { return upb_table_count(&t->t); } @@ -89,43 +87,43 @@ INLINE uint32_t upb_strtable_count(struct upb_strtable *t) { * the hashtable (the amount of data copied comes from entry_size when the * table was constructed). Therefore the data at val may be freed once the * call returns. */ -void upb_inttable_insert(struct upb_inttable *t, struct upb_inttable_entry *e); -void upb_strtable_insert(struct upb_strtable *t, struct upb_strtable_entry *e); +void upb_inttable_insert(upb_inttable *t, upb_inttable_entry *e); +void upb_strtable_insert(upb_strtable *t, upb_strtable_entry *e); -INLINE uint32_t upb_inttable_bucket(struct upb_inttable *t, upb_inttable_key_t k) { +INLINE uint32_t upb_inttable_bucket(upb_inttable *t, upb_inttable_key_t k) { return (k & t->t.mask) + 1; /* Identity hash for ints. */ } -/* Looks up key in this table. Inlined because this is in the critical path - * of parsing. We have the caller specify the entry_size because fixing - * this as a literal (instead of reading table->entry_size) gives the - * compiler more ability to optimize. */ -INLINE void *upb_inttable_fast_lookup(struct upb_inttable *t, - uint32_t key, uint32_t entry_size) { +/* Looks up key in this table. Inlined because this is in the critical path of + * decoding. We have the caller specify the entry_size because fixing this as + * a literal (instead of reading table->entry_size) gives the compiler more + * ability to optimize. */ +INLINE void *upb_inttable_fastlookup(upb_inttable *t, uint32_t key, + uint32_t entry_size) { assert(key != 0); uint32_t bucket = upb_inttable_bucket(t, key); - struct upb_inttable_entry *e; + upb_inttable_entry *e; do { - e = (struct upb_inttable_entry*)UPB_INDEX(t->t.entries, bucket-1, entry_size); + e = (upb_inttable_entry*)UPB_INDEX(t->t.entries, bucket-1, entry_size); if(e->key == key) return e; } while((bucket = e->next) != UPB_END_OF_CHAIN); return NULL; /* Not found. */ } -INLINE void *upb_inttable_lookup(struct upb_inttable *t, uint32_t key) { - return upb_inttable_fast_lookup(t, key, t->t.entry_size); +INLINE void *upb_inttable_lookup(upb_inttable *t, uint32_t key) { + return upb_inttable_fastlookup(t, key, t->t.entry_size); } -void *upb_strtable_lookup(struct upb_strtable *t, upb_strptr key); +void *upb_strtable_lookup(upb_strtable *t, upb_strptr key); /* Provides iteration over the table. The order in which the entries are * returned is undefined. Insertions invalidate iterators. The _next * functions return NULL when the end has been reached. */ -void *upb_inttable_begin(struct upb_inttable *t); -void *upb_inttable_next(struct upb_inttable *t, struct upb_inttable_entry *cur); +void *upb_inttable_begin(upb_inttable *t); +void *upb_inttable_next(upb_inttable *t, upb_inttable_entry *cur); -void *upb_strtable_begin(struct upb_strtable *t); -void *upb_strtable_next(struct upb_strtable *t, struct upb_strtable_entry *cur); +void *upb_strtable_begin(upb_strtable *t); +void *upb_strtable_next(upb_strtable *t, upb_strtable_entry *cur); #ifdef __cplusplus } /* extern "C" */ -- cgit v1.2.3