From 4d0879d2c014092282e00847ae0954113d9b7f51 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Tue, 12 Sep 2023 18:19:56 -0700 Subject: [PATCH] Do fewer intermediary allocations when calculating test methods 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 -