Skip to content

Commit fbb6be5

Browse files
committed
Simplify @Responses hash initialization
@Responses hash needs to be initialized with mime types that we get from Collector#collect_mimes_from_class_level. Mime::Type class as key and nil as value. This need to happen before content negotiation. Before that, it was looping though mime types and executing mime-type-generated method inside collector (see AbstractController::Collector#generate_method_for_mime). That approach resulted in 2 unnecessary method calls for each mime type collected by Collector#collect_mimes_from_class_level. Now hash is initialized in place, without usage of Collector#custom method.
1 parent 4aae538 commit fbb6be5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

actionpack/lib/action_controller/metal/mime_responds.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ class Collector
430430

431431
def initialize(mimes)
432432
@responses = {}
433-
mimes.each { |mime| send(mime) }
433+
434+
mimes.each { |mime| @responses["Mime::#{mime.upcase}".constantize] = nil }
434435
end
435436

436437
def any(*args, &block)

0 commit comments

Comments
 (0)