Skip to content

Commit 2625e8c

Browse files
authored
Merge pull request ruby#678 from byroot/rvalue-stack
Use batch APIs to create Array and Hash objects
2 parents 87b063a + d0d4c1d commit 2625e8c

File tree

4 files changed

+539
-166
lines changed

4 files changed

+539
-166
lines changed

ext/json/ext/fbuffer/fbuffer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ typedef unsigned char _Bool;
3636
#endif
3737

3838
enum fbuffer_type {
39-
HEAP = 0,
40-
STACK = 1,
39+
FBUFFER_HEAP_ALLOCATED = 0,
40+
FBUFFER_STACK_ALLOCATED = 1,
4141
};
4242

4343
typedef struct FBufferStruct {
@@ -73,15 +73,15 @@ static void fbuffer_stack_init(FBuffer *fb, unsigned long initial_length, char *
7373
{
7474
fb->initial_length = (initial_length > 0) ? initial_length : FBUFFER_INITIAL_LENGTH_DEFAULT;
7575
if (stack_buffer) {
76-
fb->type = STACK;
76+
fb->type = FBUFFER_STACK_ALLOCATED;
7777
fb->ptr = stack_buffer;
7878
fb->capa = stack_buffer_size;
7979
}
8080
}
8181

8282
static void fbuffer_free(FBuffer *fb)
8383
{
84-
if (fb->ptr && fb->type == HEAP) {
84+
if (fb->ptr && fb->type == FBUFFER_HEAP_ALLOCATED) {
8585
ruby_xfree(fb->ptr);
8686
}
8787
}
@@ -105,10 +105,10 @@ static void fbuffer_do_inc_capa(FBuffer *fb, unsigned long requested)
105105
for (required = fb->capa; requested > required - fb->len; required <<= 1);
106106

107107
if (required > fb->capa) {
108-
if (fb->type == STACK) {
108+
if (fb->type == FBUFFER_STACK_ALLOCATED) {
109109
const char *old_buffer = fb->ptr;
110110
fb->ptr = ALLOC_N(char, required);
111-
fb->type = HEAP;
111+
fb->type = FBUFFER_HEAP_ALLOCATED;
112112
MEMCPY(fb->ptr, old_buffer, char, fb->len);
113113
} else {
114114
REALLOC_N(fb->ptr, char, required);

ext/json/ext/parser/extconf.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
require 'mkmf'
33

44
have_func("rb_enc_interned_str", "ruby.h") # RUBY_VERSION >= 3.0
5-
have_func("rb_gc_mark_locations") # Missing on TruffleRuby
5+
have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2
6+
have_func("rb_gc_mark_locations", "ruby.h") # Missing on TruffleRuby
7+
have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
8+
69
append_cflags("-std=c99")
710

811
create_makefile 'json/ext/parser'

0 commit comments

Comments
 (0)