Permalink
Browse files

Perf: speed up 2 methods in railties.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent dc2f26c commit 8cfc6012f443f17fa51fe22aefa25323e87338b5 @miloops miloops committed with spastorino Sep 22, 2010
Showing with 2 additions and 5 deletions.
  1. +1 −1 railties/lib/rails/code_statistics.rb
  2. +1 −4 railties/lib/rails/generators.rb
@@ -23,7 +23,7 @@ def to_s
private
def calculate_statistics
- @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
+ Hash[@pais.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
@nono

nono Sep 23, 2010

Contributor

@pairs has become @pais (without the r). Typo?

@josevalim

josevalim Sep 23, 2010

Contributor

Yes! Patch please? If you can include a failing test (look here http://github.com/rails/rails/blob/master/railties/test/application/rake_test.rb) you win extra internet hugs. :)

@miloops

miloops Sep 24, 2010

Contributor

Hey,

Sorry for the typo, changed it and ran tests, everything was passing but only because it wasn't tested.

Fixed and added sanity test here: http://github.com/rails/rails/commit/63039b9c3356f73421b3742134959014d81973b0

end
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
@@ -140,10 +140,7 @@ def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
lookup(lookups)
- namespaces = subclasses.inject({}) do |hash, klass|
- hash[klass.namespace] = klass
- hash
- end
+ namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }]
lookups.each do |namespace|
klass = namespaces[namespace]

0 comments on commit 8cfc601

Please sign in to comment.