Skip to content

Commit

Permalink
Refactor ary_heap_free_ptr and remove ary_heap_free
Browse files Browse the repository at this point in the history
This PR does the following:

* `ary_heap_free_ptr` took an `ary` but it wasn't used for anything. The
code that was using `ary` was removed in ruby#7942.
* since removing the `ary` argument, there's less value in having a
separate function for `ary_heap_free`. I deleted it in favor of calling
`ary_heap_free_ptr`.
  • Loading branch information
eileencodes authored and hsbt committed Sep 20, 2024
1 parent 2230ac4 commit 8495ba4
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,11 @@ ary_heap_alloc_buffer(size_t capa)
}

static void
ary_heap_free_ptr(VALUE ary, const VALUE *ptr, long size)
ary_heap_free_ptr(const VALUE *ptr, long size)
{
ruby_sized_xfree((void *)ptr, size);
}

static void
ary_heap_free(VALUE ary)
{
ary_heap_free_ptr(ary, ARY_HEAP_PTR(ary), ARY_HEAP_SIZE(ary));
}

static size_t
ary_heap_realloc(VALUE ary, size_t new_capa)
{
Expand All @@ -391,7 +385,7 @@ rb_ary_make_embedded(VALUE ary)

MEMCPY((void *)ARY_EMBED_PTR(ary), (void *)buf, VALUE, len);

ary_heap_free_ptr(ary, buf, len * sizeof(VALUE));
ary_heap_free_ptr(buf, len * sizeof(VALUE));
}
}

Expand Down Expand Up @@ -426,7 +420,7 @@ ary_resize_capa(VALUE ary, long capacity)

if (len > capacity) len = capacity;
MEMCPY((VALUE *)RARRAY(ary)->as.ary, ptr, VALUE, len);
ary_heap_free_ptr(ary, ptr, old_capa);
ary_heap_free_ptr(ptr, old_capa);

FL_SET_EMBED(ary);
ARY_SET_LEN(ary, len);
Expand Down Expand Up @@ -489,7 +483,7 @@ static void
rb_ary_reset(VALUE ary)
{
if (ARY_OWNS_HEAP_P(ary)) {
ary_heap_free(ary);
ary_heap_free_ptr(ARY_HEAP_PTR(ary), ARY_HEAP_SIZE(ary));
}
else if (ARY_SHARED_P(ary)) {
rb_ary_unshare(ary);
Expand Down Expand Up @@ -879,7 +873,7 @@ rb_ary_free(VALUE ary)
}

RB_DEBUG_COUNTER_INC(obj_ary_ptr);
ary_heap_free(ary);
ary_heap_free_ptr(ARY_HEAP_PTR(ary), ARY_HEAP_SIZE(ary));
}
else {
RB_DEBUG_COUNTER_INC(obj_ary_embed);
Expand Down Expand Up @@ -3472,7 +3466,7 @@ rb_ary_sort_bang(VALUE ary)
rb_ary_unshare(ary);
}
else {
ary_heap_free(ary);
ary_heap_free_ptr(ARY_HEAP_PTR(ary), ARY_HEAP_SIZE(ary));
}
ARY_SET_PTR(ary, ARY_HEAP_PTR(tmp));
ARY_SET_HEAP_LEN(ary, len);
Expand Down

0 comments on commit 8495ba4

Please sign in to comment.