diff options
author | claudiob <claudiob@gmail.com> | 2014-10-17 11:38:00 -0700 |
---|---|---|
committer | Zachary Scott <e@zzak.io> | 2014-10-18 12:59:51 -0700 |
commit | 0ab075e75f58bf403f7ebe20546c7005f35db1f6 (patch) | |
tree | cf25b9db97e8a06eed8a4b32d451fae0704ee1bc /railties/lib/rails/generators/actions | |
parent | fd56b51f9bd9a472a464f7fb5ba40560156cd557 (diff) | |
download | rails-0ab075e75f58bf403f7ebe20546c7005f35db1f6.tar.gz rails-0ab075e75f58bf403f7ebe20546c7005f35db1f6.tar.bz2 rails-0ab075e75f58bf403f7ebe20546c7005f35db1f6.zip |
Replace (slower) block.call with (faster) yield
Performance optimization: `yield` with an implicit `block` is faster than `block.call`.
See http://youtu.be/fGFM_UrSp70?t=10m35s and the following benchmark:
```ruby
require 'benchmark/ips'
def fast
yield
end
def slow(&block)
block.call
end
Benchmark.ips do |x|
x.report('fast') { fast{} }
x.report('slow') { slow{} }
end
# => fast 154095 i/100ms
# => slow 71454 i/100ms
# =>
# => fast 7511067.8 (±5.0%) i/s - 37445085 in 4.999660s
# => slow 1227576.9 (±6.8%) i/s - 6145044 in 5.028356s
```
Diffstat (limited to 'railties/lib/rails/generators/actions')
-rw-r--r-- | railties/lib/rails/generators/actions/create_migration.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/actions/create_migration.rb b/railties/lib/rails/generators/actions/create_migration.rb index 682092fdf2..cffdef6ec9 100644 --- a/railties/lib/rails/generators/actions/create_migration.rb +++ b/railties/lib/rails/generators/actions/create_migration.rb @@ -39,7 +39,7 @@ module Rails protected - def on_conflict_behavior(&block) + def on_conflict_behavior options = base.options.merge(config) if identical? say_status :identical, :blue, relative_existing_migration @@ -48,7 +48,7 @@ module Rails say_status :create, :green unless pretend? ::FileUtils.rm_rf(existing_migration) - block.call + yield end elsif options[:skip] say_status :skip, :yellow |