Skip to content

Commit 302b966

Browse files
committed
Improve check for GC.stat(:total_allocated_objects)
* This works whether the Ruby implementation raises or uses a Hash with a default of 0 to represent unknown keys (like TruffleRuby) and so this is more portable. * Also avoids an extra exception on JRuby.
1 parent 06beead commit 302b966

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

activesupport/lib/active_support/notifications/instrumenter.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,14 @@ def now_cpu # rubocop:disable Lint/DuplicateMethods
158158
end
159159
end
160160

161-
begin
162-
GC.stat(:total_allocated_objects)
163-
rescue ArgumentError # Likely on JRuby
161+
if GC.stat.key?(:total_allocated_objects)
164162
def now_allocations
165-
0
166-
end
167-
else
168-
def now_allocations # rubocop:disable Lint/DuplicateMethods
169163
GC.stat(:total_allocated_objects)
170164
end
165+
else # Likely on JRuby, TruffleRuby
166+
def now_allocations
167+
0
168+
end
171169
end
172170
end
173171
end

0 commit comments

Comments
 (0)