-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mo fasta and mo betta the url_for #5750
Conversation
_routes.url_for(url_options) | ||
when Hash | ||
symbolized = {} | ||
options.keys.each do |k| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a private method to do this?
Something like this:
def merge_hash(target, base)
base.keys.each do |k|
sym = k.to_sym
target[sym] = base[k] unless target.has_key?(sym)
end
target
end
and call it like this:
symbolized = {}
merge_hash(symbolized, options)
merge_hash(symbolized, url_options)
_routes.url_for(symbolized)
What did you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did, but if you read the previous discussion people are worried about 1.0 vs 0.4 seconds for 1_000_000 iterations. adding a function call won't help you there. personally i would, but it seems contrary to the goal of making it as fast as possible. again, i'd personally go for well factored code and let the byte code writers get busy.... /cc @tenderlove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca this also makes the same bad assumption the current does: that target is symbolized. the bugz being caused can be summarized as
"we can't know if options or url_options has had string or symbol keys written into it"
mo fasta and mo betta the url_for
incorporated @tenderlove's suggestions.