提交 4d47220d 编写于 作者: S schneems

Perf optimization for `url_for` called w/ Hash

Benchmarking the existing code:

```ruby
{ :only_path => options[:host].nil? }.merge!(options.symbolize_keys)) 
```

Against optimized code, that does not require a new hash or a merge:

```ruby
options = options.symbolize_keys
options[:only_path] = options[:host].nil? unless options.key?(:only_path)
options
```

We see a statistically significant performance gain:

![](https://www.dropbox.com/s/onocpc0zfw4kjxl/Screenshot%202014-08-14%2012.45.30.png?dl=1)

Updated to not mutate incoming parameters
上级 71e8f199
......@@ -82,7 +82,9 @@ def url_for(options = nil)
when nil
super({:only_path => true})
when Hash
super({ :only_path => options[:host].nil? }.merge!(options.symbolize_keys))
options = options.symbolize_keys
options[:only_path] = options[:host].nil? unless options.key?(:only_path)
super(options)
when :back
_back_url
when Symbol
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册