зеркало из https://github.com/github/ruby.git
* 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(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
d7009f76ef
Коммит
78cfcbc657
|
@ -1,3 +1,11 @@
|
|||
Thu Nov 28 17:14:14 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* 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@tmm1.net>
|
||||
|
||||
* gc.c: Expose details about last garbage collection via GC.stat.
|
||||
|
|
2
hash.c
2
hash.c
|
@ -1713,7 +1713,7 @@ rb_hash_keys(VALUE hash)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
|
|||
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);
|
||||
|
|
26
st.c
26
st.c
|
@ -1091,10 +1091,10 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
|
|||
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, st_index_t size)
|
|||
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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче