1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* st.c (unpack_entries): use union instead of casted pointer.

patched by Sokolov Yura <funny.falcon AT gmail.com>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-05 03:44:05 +00:00
parent 5bd91964b2
commit 4a8c531a26
3 changed files with 24 additions and 10 deletions

View file

@ -1,4 +1,7 @@
Mon Mar 5 12:43:53 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
Mon Mar 5 12:44:03 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* st.c (unpack_entries): use union instead of casted pointer.
patched by Sokolov Yura <funny.falcon AT gmail.com>.
* st.c: use PACKED_ENT and FIND_ENTRY. patched by Sokolov
Yura <funny.falcon AT gmail.com>.

View file

@ -91,8 +91,13 @@ struct st_table {
__extension__
#endif
st_index_t num_entries : ST_INDEX_BITS - 1;
struct st_table_entry **bins;
struct st_table_entry *head, *tail;
union {
struct {
struct st_table_entry **bins;
struct st_table_entry *head, *tail;
} big;
struct st_packed_bins *packed;
} as;
};
#define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)

20
st.c
View file

@ -38,7 +38,7 @@ typedef struct st_packed_entry {
#define PACKED_UNIT (int)(sizeof(st_packed_entry) / sizeof(st_table_entry*))
#define MAX_PACKED_HASH (int)(ST_DEFAULT_PACKED_TABLE_SIZE * sizeof(st_table_entry*) / sizeof(st_packed_entry))
typedef struct {
typedef struct st_packed_bins {
st_packed_entry kv[MAX_PACKED_HASH];
} st_packed_bins;
@ -105,14 +105,20 @@ st_realloc_bins(st_table_entry **bins, st_index_t newsize, st_index_t oldsize)
return bins;
}
/* Shortage */
#define bins as.big.bins
#define head as.big.head
#define tail as.big.tail
/* preparation for possible packing improvements */
#define PACKED_BINS(table) (*(st_packed_bins *)(table)->bins)
#define PACKED_BINS(table) (*(table)->as.packed)
#define PACKED_ENT(table, i) PACKED_BINS(table).kv[i]
#define PKEY(table, i) PACKED_ENT((table), (i)).key
#define PVAL(table, i) PACKED_ENT((table), (i)).val
#define PHASH(table, i) PKEY((table), (i))
#define PKEY_SET(table, i, v) (PKEY((table), (i)) = (v))
#define PVAL_SET(table, i, v) (PVAL((table), (i)) = (v))
/* this function depends much on packed layout, so that it placed here */
static inline void
remove_packed_entry(st_table *table, st_index_t i)
@ -475,7 +481,7 @@ unpack_entries(register st_table *table)
st_table tmp_table = *table;
packed_bins = PACKED_BINS(table);
table->bins = (st_table_entry **)&packed_bins;
table->as.packed = &packed_bins;
tmp_table.entries_packed = 0;
tmp_table.num_entries = 0;
#if ST_DEFAULT_INIT_TABLE_SIZE == ST_DEFAULT_PACKED_TABLE_SIZE
@ -607,7 +613,7 @@ st_table*
st_copy(st_table *old_table)
{
st_table *new_table;
st_table_entry *ptr, *entry, *prev, **tail;
st_table_entry *ptr, *entry, *prev, **tailp;
st_index_t num_bins = old_table->num_bins;
st_index_t hash_val;
@ -631,7 +637,7 @@ st_copy(st_table *old_table)
if ((ptr = old_table->head) != 0) {
prev = 0;
tail = &new_table->head;
tailp = &new_table->head;
do {
entry = st_alloc_entry();
if (entry == 0) {
@ -643,8 +649,8 @@ st_copy(st_table *old_table)
entry->next = new_table->bins[hash_val];
new_table->bins[hash_val] = entry;
entry->back = prev;
*tail = prev = entry;
tail = &entry->fore;
*tailp = prev = entry;
tailp = &entry->fore;
} while ((ptr = ptr->fore) != 0);
new_table->tail = prev;
}