From b426e1b1fafdab688c646cef8245fa72403d37bb Mon Sep 17 00:00:00 2001 From: glass Date: Wed, 27 Nov 2013 16:07:10 +0000 Subject: * st.c (st_keys): define st_keys(). it writes each key to buffer. * hash.c (rb_hash_keys): use st_keys() for performance improvement if st_data_t and VALUE are compatible. * st.h: define macro ST_DATA_COMPATIBLE_P() to predicate whether st_data_t and passed type are compatible. * configure.in: check existence of builtin function to use in ST_DATA_COMPATIBLE_P(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- include/ruby/st.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/ruby') diff --git a/include/ruby/st.h b/include/ruby/st.h index e71301b519..fa6190dcd6 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -59,6 +59,13 @@ struct st_hash_type { #define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT) +#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P) +# define ST_DATA_COMPATIBLE_P(type) \ + __builtin_choose_expr(__builtin_types_compatible_p(type, st_data_t), 1, 0) +#else +# define ST_DATA_COMPATIBLE_P(type) 0 +#endif + struct st_table { const struct st_hash_type *type; st_index_t num_bins; @@ -112,6 +119,7 @@ int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_ 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); 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); -- cgit v1.2.3