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

ruby-changes:31815

From: glass <ko1@a...>
Date: Thu, 28 Nov 2013 17:15:34 +0900 (JST)
Subject: [ruby-changes:31815] glass:r43894 (trunk): * st.c (st_keys): fix not to use Qundef in st.c.

glass	2013-11-28 17:15:26 +0900 (Thu, 28 Nov 2013)

  New Revision: 43894

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

  Log:
    * st.c (st_keys): fix not to use Qundef in st.c.
    
    * include/ruby/st.h: define modified prototype.
    
    * hash.c (rb_hash_keys): use modified st_keys().

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/include/ruby/st.h
    trunk/st.c
Index: include/ruby/st.h
===================================================================
--- include/ruby/st.h	(revision 43893)
+++ include/ruby/st.h	(revision 43894)
@@ -120,6 +120,7 @@ int st_foreach(st_table *, int (*)(ANYAR https://github.com/ruby/ruby/blob/trunk/include/ruby/st.h#L120
 int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t);
 int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t);
 st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size);
+st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never);
 void st_add_direct(st_table *, st_data_t, st_data_t);
 void st_free_table(st_table *);
 void st_cleanup_safe(st_table *, st_data_t);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43893)
+++ ChangeLog	(revision 43894)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Nov 28 17:14:14 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* st.c (st_keys): fix not to use Qundef in st.c.
+
+	* include/ruby/st.h: define modified prototype.
+
+	* hash.c (rb_hash_keys): use modified st_keys().
+
 Thu Nov 28 16:34:43 2013  Aman Gupta <ruby@t...>
 
 	* gc.c: Expose details about last garbage collection via GC.stat.
Index: st.c
===================================================================
--- st.c	(revision 43893)
+++ st.c	(revision 43894)
@@ -1091,10 +1091,10 @@ st_foreach(st_table *table, int (*func)( https://github.com/ruby/ruby/blob/trunk/st.c#L1091
     return 0;
 }
 
-st_index_t
-st_keys(st_table *table, st_data_t *keys, st_index_t size)
+static st_index_t
+get_keys(st_table *table, st_data_t *keys, st_index_t size, int check, st_data_t never)
 {
-    st_data_t key, never = (st_data_t)Qundef;
+    st_data_t key;
     st_data_t *keys_start = keys;
 
     if (table->entries_packed) {
@@ -1103,23 +1103,35 @@ st_keys(st_table *table, st_data_t *keys https://github.com/ruby/ruby/blob/trunk/st.c#L1103
 	if (size > table->real_entries) size = table->real_entries;
 	for (i = 0; i < size; i++) {
 	    key = PKEY(table, i);
-	    if (key == never) continue;
+	    if (check && key == never) continue;
 	    *keys++ = key;
 	}
     }
     else {
 	st_table_entry *ptr = table->head;
 	st_data_t *keys_end = keys + size;
-	while (ptr && keys < keys_end) {
+	for (; ptr && keys < keys_end; ptr = ptr->fore) {
 	    key = ptr->key;
-	    if (key != never) *keys++ = key;
-	    ptr = ptr->fore;
+	    if (check && key == never) continue;
+	    *keys++ = key;
 	}
     }
 
     return keys - keys_start;
 }
 
+st_index_t
+st_keys(st_table *table, st_data_t *keys, st_index_t size)
+{
+    return get_keys(table, keys, size, 0, 0);
+}
+
+st_index_t
+st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never)
+{
+    return get_keys(table, keys, size, 1, never);
+}
+
 #if 0  /* unused right now */
 int
 st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
Index: hash.c
===================================================================
--- hash.c	(revision 43893)
+++ hash.c	(revision 43894)
@@ -1713,7 +1713,7 @@ rb_hash_keys(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1713
 
 	if (OBJ_PROMOTED(keys)) rb_gc_writebarrier_remember_promoted(keys);
 	RARRAY_PTR_USE(keys, ptr, {
-	    size = st_keys(table, ptr, size);
+	    size = st_keys_check(table, ptr, size, Qundef);
 	});
 	rb_ary_set_len(keys, size);
     }

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

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