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

ruby-changes:22264

From: shyouhei <ko1@a...>
Date: Mon, 16 Jan 2012 00:47:47 +0900 (JST)
Subject: [ruby-changes:22264] shyouhei:r34314 (trunk): st optimize st_insert

shyouhei	2012-01-16 00:46:44 +0900 (Mon, 16 Jan 2012)

  New Revision: 34314

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

  Log:
    st optimize st_insert

  Modified files:
    trunk/ChangeLog
    trunk/st.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34313)
+++ ChangeLog	(revision 34314)
@@ -1,3 +1,11 @@
+Mon Jan 16 00:41:33 2012  Sokolov Yura  <funny.falcon@g...>
+
+	* st.c: st use function instead of macro.  In my current
+	  environment (Ubunu 11.04 32bit gcc-4.5.2) it gives 4%
+	  performance improvement.
+
+	  https://github.com/ruby/ruby/pull/77
+
 Sun Jan 15 14:09:48 2012  NARUSE, Yui  <naruse@r...>
 
 	* object.c (rb_inspect): raise the result is not compatible with
Index: st.c
===================================================================
--- st.c	(revision 34313)
+++ st.c	(revision 34314)
@@ -420,11 +420,11 @@
 #undef collision_check
 #define collision_check 1
 
-static void
+static inline void
 add_direct(st_table * table, st_data_t key, st_data_t value,
-	st_index_t hash_val, st_index_t bin_pos)
+	st_index_t hash_val, register st_index_t bin_pos)
 {
-    st_table_entry *entry;
+    register st_table_entry *entry;
     if (table->num_entries > ST_DEFAULT_MAX_DENSITY * table->num_bins) {
 	rehash(table);
         bin_pos = hash_val % table->num_bins;
@@ -432,10 +432,11 @@
 
     entry = st_alloc_entry();
 
+    entry->next = table->bins[bin_pos];
+    table->bins[bin_pos] = entry;
     entry->hash = hash_val;
     entry->key = key;
     entry->record = value;
-    entry->next = table->bins[bin_pos];
     if (table->head != 0) {
 	entry->fore = 0;
 	(entry->back = table->tail)->fore = entry;
@@ -445,7 +446,6 @@
 	table->head = table->tail = entry;
 	entry->fore = entry->back = 0;
     }
-    table->bins[bin_pos] = entry;
     table->num_entries++;
 }
 
@@ -487,7 +487,8 @@
 int
 st_insert(register st_table *table, register st_data_t key, st_data_t value)
 {
-    st_index_t hash_val, bin_pos;
+    st_index_t hash_val;
+    register st_index_t bin_pos;
     register st_table_entry *ptr;
 
     if (table->entries_packed) {
@@ -518,7 +519,8 @@
 st_insert2(register st_table *table, register st_data_t key, st_data_t value,
 	   st_data_t (*func)(st_data_t))
 {
-    st_index_t hash_val, bin_pos;
+    st_index_t hash_val;
+    register st_index_t bin_pos;
     register st_table_entry *ptr;
 
     if (table->entries_packed) {
@@ -549,7 +551,7 @@
 void
 st_add_direct(st_table *table, st_data_t key, st_data_t value)
 {
-    st_index_t hash_val, bin_pos;
+    st_index_t hash_val;
 
     if (table->entries_packed) {
 	add_packed_direct(table, key, value);
@@ -557,8 +559,7 @@
     }
 
     hash_val = do_hash(key, table);
-    bin_pos = hash_val % table->num_bins;
-    add_direct(table, key, value, hash_val, bin_pos);
+    add_direct(table, key, value, hash_val, hash_val % table->num_bins);
 }
 
 static void

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

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