Skip to content

Instantly share code, notes, and snippets.

@mje113
Created June 25, 2013 15:41
Show Gist options
  • Save mje113/5859525 to your computer and use it in GitHub Desktop.
Save mje113/5859525 to your computer and use it in GitHub Desktop.
Performance improvement for ActionController::Responder#to_format
# 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