summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-05 04:49:01 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-05 04:49:01 +0000
commitce7f3e13c16fffe4fc7b47bdad8abc15bf7206f1 ()
tree66a0f1642b67696014252506f24642ec34a9c4b2 /st.c
parente06a663089f917f2d5bf37ab857817603caa0d5a (diff)
optimize rb_hash_bulk_insert to generally outperform 2.4.
Specialized routine for small linear-probling hash instances to boost creation of such things [Bug #13861] Signed-off-by: Urabe, Shyouhei <[email protected]> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--st.c92
1 files changed, 67 insertions, 25 deletions
@@ -2102,42 +2102,84 @@ st_rehash(st_table *tab)
}
#ifdef RUBY
-/* Mimics ruby's { foo => bar } syntax. This function is placed here
- because it touches table internals and write barriers at once. */
-void
-rb_hash_bulk_insert(long argc, const VALUE *argv, VALUE hash)
{
- int i;
- st_table *tab;
- st_assert(argc % 2);
- if (! argc)
- return;
- if (! RHASH(hash)->ntbl)
- rb_hash_tbl_raw(hash);
- tab = RHASH(hash)->ntbl;
- /* make room */
- st_expand_table(tab, tab->num_entries + argc);
/* push elems */
for (i = 0; i < argc; /* */) {
VALUE key = argv[i++];
VALUE val = argv[i++];
- st_data_t k = (rb_obj_class(key) == rb_cString) ?
- rb_str_new_frozen(key) : key;
- st_table_entry e;
- e.hash = do_hash(k, tab);
- e.key = k;
- e.record = val;
-
- tab->entries[tab->entries_bound++] = e;
- tab->num_entries++;
- RB_OBJ_WRITTEN(hash, Qundef, k);
- RB_OBJ_WRITTEN(hash, Qundef, val);
}
/* reindex */
st_rehash(tab);
}
#endif