Permalink
Browse files

Performance fix for AttributeSet#each.

Using uniq on attributes array is slow, because it must compare
attributes to each other. This change makes initialization of a new
object with Virtus attributes 3 times faster.
  • Loading branch information...
1 parent d344e5b commit c2dc794e22d1da559e42462d6220595e115b9985 @Antti Antti committed Oct 23, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/virtus/attribute_set.rb
@@ -43,7 +43,7 @@ def initialize(parent = nil, attributes = [])
# @api public
def each
return to_enum unless block_given?
- @index.values.uniq.each { |attribute| yield attribute }
+ @index.each { |name, attribute| yield attribute if name.kind_of?(Symbol) }
self
end

0 comments on commit c2dc794

Please sign in to comment.