Skip to content

Commit 8ecd4dd

Browse files
authored
Reduce allocations in Slotable#register_default_slots (#2328)
* Add render_inline_allocations for ruby 3.4.3 * Reduce allocations in Slotable#register_default_slots
1 parent 9f3f4fd commit 8ecd4dd

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 6
1010

1111
## main
1212

13+
* Reduce string allocations during compilation.
14+
15+
*Jonathan del Strother*
16+
1317
## 3.23.2
1418

1519
* Include .tt files in published gem. Fixes templates not being available when using generators.

lib/view_component/slotable.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ def register_polymorphic_slot(slot_name, types, collection:)
271271
# Called by the compiler, as instance methods are not defined when slots are first registered
272272
def register_default_slots
273273
registered_slots.each do |slot_name, config|
274-
config[:default_method] = instance_methods.find { |method_name| method_name == :"default_#{slot_name}" }
274+
default_method_name = :"default_#{slot_name}"
275+
config[:default_method] = instance_methods.find { |method_name| method_name == default_method_name }
275276

276277
registered_slots[slot_name] = config
277278
end

test/sandbox/test/rendering_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def test_render_inline_allocations
1919
if Rails.version.to_f < 8.0
2020
{"3.3.8" => 124, "3.3.0" => 140, "3.2.8" => 122, "3.1.7" => 122, "3.0.7" => 131}
2121
elsif Rails.version.split(".").first(2).map(&:to_i) == [8, 0]
22-
{"3.5.0" => 117, "3.4.4" => 121, "3.3.8" => 133}
22+
{"3.5.0" => 117, "3.4.4" => 121, "3.4.3" => 121, "3.3.8" => 133}
2323
else
24-
{"3.4.4" => 119}
24+
{"3.4.4" => 119, "3.4.3" => 119}
2525
end
2626

2727
assert_allocations(**allocations) do

0 commit comments

Comments
 (0)