Created
June 25, 2013 15:41
-
-
Save mje113/5859525 to your computer and use it in GitHub Desktop.
Performance improvement for ActionController::Responder#to_format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Orignal | |
module ActionController | |
class Responder | |
def to_format | |
if get? || !has_errors? || response_overridden? | |
default_render | |
else | |
display_errors | |
end | |
rescue ActionView::MissingTemplate => e | |
api_behavior(e) | |
end | |
end | |
end | |
# Becomes: | |
module ActionController | |
class Responder | |
def to_format | |
begin | |
return begin | |
if get? || !has_errors? || response_overridden? | |
default_render | |
else | |
display_errors | |
end | |
end | |
rescue ActionView::MissingTemplate => e | |
api = -> { api_behavior(e) } | |
end | |
api.call | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment