Browse files

Implement Gem::Specification#to_ary

This is a perf fix. Array#flatten is called in places which contain
nested arrays of spec objects. (For example in
Gem::Specification.find_in_unresolved.) Due to Ruby's implementation of
Array#flatten, it will hit method_missing to try to dispatch the #to_ary
method, which is slow. Implementing a #to_ary like this prevents
method_missing getting called.
  • Loading branch information...
1 parent c4223a2 commit 54cf153b2c5fe3b2b9ac958bc62cb7781c4a1915 @jonleighton committed Feb 8, 2013
Showing with 5 additions and 0 deletions.
  1. +5 −0 lib/rubygems/specification.rb
@@ -1880,6 +1880,11 @@ def method_missing(sym, *a, &b) # :nodoc:
+ # Prevent ruby hitting spec.method_missing when [[spec]].flatten is called
+ def to_ary # :nodoc:
+ nil
+ end
# Normalize the list of files so that:
# * All file lists have redundancies removed.

0 comments on commit 54cf153

Please sign in to comment.