mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
d1abf29e79
Removing this feature causes boost in performance when using Ruby 1.9. Ruby 1.9 started to do implicit conversions using `to_ary` and `to_str` in some STDLIB methods (like Array#join). To do such implicit conversions, Ruby 1.9 always dispatches the method and rescues the NoMethodError exception in case one is raised. Therefore, since the whiners feature defined NilClass#method_missing, such implicit conversions for nil became much, much slower. In fact, just defining NilClass#method_missing (even without the whiners feature) already causes a massive slow down. Here is a snippet that shows such slow down: require "benchmark" Benchmark.realtime { 1_000.times { [nil,nil,nil].join } } class NilClass def method_missing(*args) raise NoMethodError end end Benchmark.realtime { 1_000.times { [nil,nil,nil].join } }
11 lines
277 B
Ruby
11 lines
277 B
Ruby
require 'abstract_unit'
|
|
require 'active_support/whiny_nil'
|
|
|
|
class WhinyNilTest < Test::Unit::TestCase
|
|
def test_id
|
|
nil.id
|
|
rescue RuntimeError => nme
|
|
assert_no_match(/nil:NilClass/, nme.message)
|
|
assert_match(Regexp.new(nil.object_id.to_s), nme.message)
|
|
end
|
|
end
|