summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-04-03 16:07:34 +0200
committerJean Boussier <[email protected]>2025-04-03 16:57:57 +0200
commit4aa74b605c9960192c30c711fa6e982727eb8d1b (patch)
tree116153eec31c478adb0b8ca29197383231216873
parentfab133e629c507f4add4a7dde2e0ba12b7ec281c (diff)
compile.c: avoid allocating 0 length call_data
if `body->ci_size` is `0`, there's no point allocating 0B, it just wastes an entry in the allocator.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13059
-rw-r--r--compile.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index cd7e92298c..e97c61eb10 100644
--- a/compile.c
+++ b/compile.c
@@ -2596,7 +2596,13 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
else {
body->is_entries = NULL;
}
- body->call_data = ZALLOC_N(struct rb_call_data, body->ci_size);
+
+ if (body->ci_size) {
+ body->call_data = ZALLOC_N(struct rb_call_data, body->ci_size);
+ }
+ else {
+ body->call_data = NULL;
+ }
ISEQ_COMPILE_DATA(iseq)->ci_index = 0;
// Calculate the bitmask buffer size.
@@ -13370,6 +13376,11 @@ ibf_load_ci_entries(const struct ibf_load *load,
unsigned int ci_size,
struct rb_call_data **cd_ptr)
{
+ if (!ci_size) {
+ *cd_ptr = NULL;
+ return;
+ }
+
ibf_offset_t reading_pos = ci_entries_offset;
unsigned int i;