Skip to content

Commit

Permalink
Clean up HAVE_RB_HASH_BULK_INSERT (#909)
Browse files Browse the repository at this point in the history
`rb_hash_bulk_insert` function can be used as public API since Ruby 2.7.0.
ruby/ruby@d3df725

Current Oj gem only supports Ruby 2.7.0 or later.
So there is no need to check whether function exists.
  • Loading branch information
Watson1978 authored Jan 8, 2024
1 parent b05c0b5 commit 0032fbb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 29 deletions.
2 changes: 0 additions & 2 deletions ext/oj/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
have_func('pthread_mutex_init')
have_func('rb_enc_interned_str')
have_func('rb_ext_ractor_safe', 'ruby.h')
# rb_hash_bulk_insert is deep down in a header not included in normal build and that seems to fool have_func.
have_func('rb_hash_bulk_insert', 'ruby.h') unless '2' == version[0] && '6' == version[1]

dflags['OJ_DEBUG'] = true unless ENV['OJ_DEBUG'].nil?

Expand Down
27 changes: 0 additions & 27 deletions ext/oj/usual.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,22 +281,13 @@ static void close_object(ojParser p) {
VALUE *head = d->vhead + c->vi + 1;
volatile VALUE obj = rb_hash_new();

#if HAVE_RB_HASH_BULK_INSERT
for (vp = head; kp < d->ktail; kp++, vp += 2) {
*vp = d->get_key(p, kp);
if (sizeof(kp->buf) <= (size_t)kp->len) {
OJ_R_FREE(kp->key);
}
}
rb_hash_bulk_insert(d->vtail - head, head, obj);
#else
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) <= (size_t)kp->len) {
OJ_R_FREE(kp->key);
}
}
#endif
d->ktail = d->khead + c->ki;
d->vtail = head;
head--;
Expand Down Expand Up @@ -341,22 +332,13 @@ static void close_object_create(ojParser p) {
head++;
if (Qnil == d->hash_class) {
obj = rb_hash_new();
#if HAVE_RB_HASH_BULK_INSERT
for (vp = head; kp < d->ktail; kp++, vp += 2) {
*vp = d->get_key(p, kp);
if (sizeof(kp->buf) <= (size_t)kp->len) {
OJ_R_FREE(kp->key);
}
}
rb_hash_bulk_insert(d->vtail - head, head, obj);
#else
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) <= (size_t)kp->len) {
OJ_R_FREE(kp->key);
}
}
#endif
} else {
obj = rb_class_new_instance(0, NULL, d->hash_class);
for (vp = head; kp < d->ktail; kp++, vp += 2) {
Expand All @@ -373,22 +355,13 @@ static void close_object_create(ojParser p) {
if (!d->ignore_json_create && rb_respond_to(clas, oj_json_create_id)) {
volatile VALUE arg = rb_hash_new();

#if HAVE_RB_HASH_BULK_INSERT
for (vp = head; kp < d->ktail; kp++, vp += 2) {
*vp = d->get_key(p, kp);
if (sizeof(kp->buf) <= (size_t)kp->len) {
OJ_R_FREE(kp->key);
}
}
rb_hash_bulk_insert(d->vtail - head, head, arg);
#else
for (vp = head; kp < d->ktail; kp++, vp += 2) {
rb_hash_aset(arg, d->get_key(p, kp), *(vp + 1));
if (sizeof(kp->buf) <= (size_t)kp->len) {
OJ_R_FREE(kp->key);
}
}
#endif
obj = rb_funcall(clas, oj_json_create_id, 1, arg);
} else {
obj = rb_class_new_instance(0, NULL, clas);
Expand Down

0 comments on commit 0032fbb

Please sign in to comment.