summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2024-04-24 12:18:48 -0400
committerPeter Zhu <peter@peterzhu.ca>2024-04-25 09:25:33 -0400
commitf248e1008a8f79cca801b27d512a587f65a0dd36 (patch)
tree825f2f0c13f85b3547ded100030a39a65096454e
parentb50e1e68b6050033587e9f6deaf7a104926a01ae (diff)
Embed rb_gc_function_map_t in rb_vm_t
Avoids a pointer indirection and memory allocation.
-rw-r--r--gc.c9
-rw-r--r--vm_core.h4
2 files changed, 5 insertions, 8 deletions
diff --git a/gc.c b/gc.c
index 309bfcf41b..5784ce4994 100644
--- a/gc.c
+++ b/gc.c
@@ -1890,9 +1890,6 @@ static void *rb_gc_impl_objspace_alloc(void);
void
ruby_external_gc_init()
{
- rb_gc_function_map_t *map = malloc(sizeof(rb_gc_function_map_t));
- rb_gc_functions = map;
-
char *gc_so_path = getenv("RUBY_GC_LIBRARY_PATH");
void *handle = NULL;
if (gc_so_path) {
@@ -1905,13 +1902,13 @@ ruby_external_gc_init()
# define load_external_gc_func(name) do { \
if (handle) { \
- map->name = dln_symbol(handle, "rb_gc_impl_" #name); \
- if (!map->name) { \
+ rb_gc_functions->name = dln_symbol(handle, "rb_gc_impl_" #name); \
+ if (!rb_gc_functions->name) { \
rb_bug("ruby_external_gc_init: " #name " func not exported by library %s", gc_so_path); \
} \
} \
else { \
- map->name = rb_gc_impl_##name; \
+ rb_gc_functions->name = rb_gc_impl_##name; \
} \
} while (0)
diff --git a/vm_core.h b/vm_core.h
index b0df8f5af4..e42f15c7c6 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -111,7 +111,7 @@ typedef struct gc_function_map {
void *(*objspace_alloc)(void);
} rb_gc_function_map_t;
-#define rb_gc_functions (GET_VM()->gc_functions_map)
+#define rb_gc_functions (&GET_VM()->gc_functions_map)
#endif
/*
@@ -761,7 +761,7 @@ typedef struct rb_vm_struct {
struct rb_objspace *objspace;
#if USE_SHARED_GC
- rb_gc_function_map_t *gc_functions_map;
+ rb_gc_function_map_t gc_functions_map;
#endif
rb_at_exit_list *at_exit;