зеркало из https://github.com/github/ruby.git
* st.c: add st_values() and st_values_check().
* include/ruby/st.h: add prototypes for above. * hash.c (rb_hash_values): use st_values_check() for performance improvement if VALUE and st_data_t are compatible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
78cfcbc657
Коммит
79e6336495
|
@ -1,3 +1,12 @@
|
|||
Thu Nov 28 17:34:42 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* st.c: add st_values() and st_values_check().
|
||||
|
||||
* include/ruby/st.h: add prototypes for above.
|
||||
|
||||
* hash.c (rb_hash_values): use st_values_check() for performance
|
||||
improvement if VALUE and st_data_t are compatible.
|
||||
|
||||
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.
|
||||
|
|
22
hash.c
22
hash.c
|
@ -1746,12 +1746,26 @@ values_i(VALUE key, VALUE value, VALUE ary)
|
|||
VALUE
|
||||
rb_hash_values(VALUE hash)
|
||||
{
|
||||
VALUE ary;
|
||||
VALUE values;
|
||||
st_index_t size = RHASH_SIZE(hash);
|
||||
|
||||
ary = rb_ary_new_capa(RHASH_SIZE(hash));
|
||||
rb_hash_foreach(hash, values_i, ary);
|
||||
values = rb_ary_new_capa(size);
|
||||
if (size == 0) return values;
|
||||
|
||||
return ary;
|
||||
if (ST_DATA_COMPATIBLE_P(VALUE)) {
|
||||
st_table *table = RHASH(hash)->ntbl;
|
||||
|
||||
if (OBJ_PROMOTED(values)) rb_gc_writebarrier_remember_promoted(values);
|
||||
RARRAY_PTR_USE(values, ptr, {
|
||||
size = st_values_check(table, ptr, size, Qundef);
|
||||
});
|
||||
rb_ary_set_len(values, size);
|
||||
}
|
||||
else {
|
||||
rb_hash_foreach(hash, values_i, values);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -121,6 +121,8 @@ 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);
|
||||
st_index_t st_values(st_table *table, st_data_t *values, st_index_t size);
|
||||
st_index_t st_values_check(st_table *table, st_data_t *values, 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);
|
||||
|
|
41
st.c
41
st.c
|
@ -1132,6 +1132,47 @@ 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);
|
||||
}
|
||||
|
||||
static st_index_t
|
||||
get_values(st_table *table, st_data_t *values, st_index_t size, int check, st_data_t never)
|
||||
{
|
||||
st_data_t key;
|
||||
st_data_t *values_start = values;
|
||||
|
||||
if (table->entries_packed) {
|
||||
st_index_t i;
|
||||
|
||||
if (size > table->real_entries) size = table->real_entries;
|
||||
for (i = 0; i < size; i++) {
|
||||
key = PKEY(table, i);
|
||||
if (check && key == never) continue;
|
||||
*values++ = PVAL(table, i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
st_table_entry *ptr = table->head;
|
||||
st_data_t *values_end = values + size;
|
||||
for (; ptr && values < values_end; ptr = ptr->fore) {
|
||||
key = ptr->key;
|
||||
if (check && key == never) continue;
|
||||
*values++ = ptr->record;
|
||||
}
|
||||
}
|
||||
|
||||
return values - values_start;
|
||||
}
|
||||
|
||||
st_index_t
|
||||
st_values(st_table *table, st_data_t *values, st_index_t size)
|
||||
{
|
||||
return get_values(table, values, size, 0, 0);
|
||||
}
|
||||
|
||||
st_index_t
|
||||
st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never)
|
||||
{
|
||||
return get_values(table, values, size, 1, never);
|
||||
}
|
||||
|
||||
#if 0 /* unused right now */
|
||||
int
|
||||
st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
|
||||
|
|
Загрузка…
Ссылка в новой задаче