Skip to content

Commit 52283b4

Browse files
committed
Compile RGENGC_OBJ_INFO case statically
Make this macro condition as compile-time constant instead of a preprocess-time constant, and compile the body always.
1 parent 67cc574 commit 52283b4

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

gc.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4965,12 +4965,6 @@ rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
49654965
#undef APPEND_F
49664966
#undef BUFF_ARGS
49674967

4968-
#if RGENGC_OBJ_INFO
4969-
#define OBJ_INFO_BUFFERS_NUM 10
4970-
#define OBJ_INFO_BUFFERS_SIZE 0x100
4971-
static rb_atomic_t obj_info_buffers_index = 0;
4972-
static char obj_info_buffers[OBJ_INFO_BUFFERS_NUM][OBJ_INFO_BUFFERS_SIZE];
4973-
49744968
/* Increments *var atomically and resets *var to 0 when maxval is
49754969
* reached. Returns the wraparound old *var value (0...maxval). */
49764970
static rb_atomic_t
@@ -4988,17 +4982,18 @@ atomic_inc_wraparound(rb_atomic_t *var, const rb_atomic_t maxval)
49884982
static const char *
49894983
obj_info(VALUE obj)
49904984
{
4991-
rb_atomic_t index = atomic_inc_wraparound(&obj_info_buffers_index, OBJ_INFO_BUFFERS_NUM);
4992-
char *const buff = obj_info_buffers[index];
4993-
return rb_raw_obj_info(buff, OBJ_INFO_BUFFERS_SIZE, obj);
4994-
}
4995-
#else
4996-
static const char *
4997-
obj_info(VALUE obj)
4998-
{
4985+
if (RGENGC_OBJ_INFO) {
4986+
static struct {
4987+
rb_atomic_t index;
4988+
char buffers[10][0x100];
4989+
} info = {0};
4990+
4991+
rb_atomic_t index = atomic_inc_wraparound(&info.index, numberof(info.buffers));
4992+
char *const buff = info.buffers[index];
4993+
return rb_raw_obj_info(buff, sizeof(info.buffers[0]), obj);
4994+
}
49994995
return obj_type_name(obj);
50004996
}
5001-
#endif
50024997

50034998
/*
50044999
------------------------ Extended allocator ------------------------

0 commit comments

Comments
 (0)