[前][次][番号順一覧][スレッド一覧]

ruby-changes:22854

From: nobu <ko1@a...>
Date: Mon, 5 Mar 2012 12:44:31 +0900 (JST)
Subject: [ruby-changes:22854] nobu:r34902 (trunk): * st.c (unpack_entries): use union instead of casted pointer.

nobu	2012-03-05 12:44:05 +0900 (Mon, 05 Mar 2012)

  New Revision: 34902

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34902

  Log:
    * st.c (unpack_entries): use union instead of casted pointer.
      patched by Sokolov Yura <funny.falcon AT gmail.com>.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/st.h
    trunk/st.c

Index: include/ruby/st.h
===================================================================
--- include/ruby/st.h	(revision 34901)
+++ include/ruby/st.h	(revision 34902)
@@ -91,8 +91,13 @@
     __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)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34901)
+++ ChangeLog	(revision 34902)
@@ -1,5 +1,8 @@
-Mon Mar  5 12:43:53 2012  Nobuyoshi Nakada  <nobu@r...>
+Mon Mar  5 12:44:03 2012  Nobuyoshi Nakada  <nobu@r...>
 
+	* 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>.
 
Index: st.c
===================================================================
--- st.c	(revision 34901)
+++ st.c	(revision 34902)
@@ -38,7 +38,7 @@
 #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 @@
     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 @@
     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_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 @@
 
     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 @@
 	    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;
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]