From 9c4a5231ad083abda81603a99fe9d61fe95753e4 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Thu, 21 Sep 2023 16:29:43 -0700 Subject: [PATCH] Do fewer intermediary allocations when calculating test methods (#89) Showed up as the number one hotspot when profile the rubygems.org `rails test` startup time --- lib/shoulda/context/context.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/shoulda/context/context.rb b/lib/shoulda/context/context.rb index c15b2ffc..ce1dc1fa 100644 --- a/lib/shoulda/context/context.rb +++ b/lib/shoulda/context/context.rb @@ -100,7 +100,7 @@ def test_unit_class def test_methods @test_methods ||= Hash.new { |h,k| - h[k] = Hash[k.instance_methods.map { |n| [n, true] }] + h[k] = k.instance_methods.each_with_object({}) { |n, a| a[n] = true } } end @@ -213,4 +213,3 @@ def method_missing(method, *args, &blk) class DuplicateTestError < RuntimeError; end end end -