Skip to content

Commit 0b511ad

Browse files
nimmoloclaude
andcommitted
Move Array allocation outside loop in select options
Avoids allocating a new array on each iteration when checking if a value is selected. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5a61bd5 commit 0b511ad

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/superform/rails/components/select.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def view_template(&block)
4747
end
4848

4949
def options(*collection)
50+
# Handle both single values and arrays (for multiple selects)
51+
selected_values = Array(field.value)
5052
map_options(collection).each do |key, value|
51-
# Handle both single values and arrays (for multiple selects)
52-
selected = Array(field.value).include?(key)
53-
option(selected: selected, value: key) { value }
53+
option(selected: selected_values.include?(key), value: key) { value }
5454
end
5555
end
5656

0 commit comments

Comments
 (0)