Skip to content

Commit 56f393b

Browse files
Add comment to performance optimization
1 parent 5b60000 commit 56f393b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/values.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def self.new(*fields, &block)
2323
Class.new do
2424
attr_reader(:hash, *fields)
2525

26+
# Unroll the fields into a series of assignment Ruby statements that can
27+
# be used inside of the initializer for the new class. This was introduced
28+
# in PR#56 as a performance optimization -- it ensures that this iteration
29+
# happens once per class, instead of happening once per instance of the
30+
# class.
2631
instance_var_assignments = Array.new(fields.length) do |idx|
2732
"@#{fields[idx]} = values[#{idx}]"
2833
end.join("\n")

0 commit comments

Comments
 (0)