Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up HAVE_RB_HASH_BULK_INSERT #909

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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