aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorSemyon Perepelitsa <sema@sema.in>2012-01-21 18:15:08 +0800
committerSemyon Perepelitsa <sema@sema.in>2012-01-21 18:32:17 +0800
commitbb1813cab859a404ffbb0bc8077407632b92a2f1 (patch)
treea2e75982e4129af1363d6cbed22fa2d1079a882f /activesupport/lib
parent2e13850e4c8245214568b7e133908af7db9dbb9f (diff)
downloadrails-bb1813cab859a404ffbb0bc8077407632b92a2f1.tar.gz
rails-bb1813cab859a404ffbb0bc8077407632b92a2f1.tar.bz2
rails-bb1813cab859a404ffbb0bc8077407632b92a2f1.zip
Replace regexp matching with a simple string manipulation.
Using regexp looks like overkill here and is also 2x slower. user system total real string 0.020000 0.000000 0.020000 ( 0.016256) regexp 0.030000 0.000000 0.030000 ( 0.035360) require "benchmark" names = ("a".."z").map { |c| c + "a" * rand(5..10) + "=" * rand(0..1) }.map(&:to_sym) puts names n = 1000 Benchmark.bmbm do |x| x.report "string" do n.times do names.each do |name| string_name = name.to_s string_name.chomp!('=') string_name end end end x.report "regexp" do n.times do names.each do |name| name.to_s =~ /(.*)=$/ $1 end end end end
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/ordered_options.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index bf81567d22..9e5a5d0246 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -30,8 +30,9 @@ module ActiveSupport #:nodoc:
end
def method_missing(name, *args)
- if name.to_s =~ /(.*)=$/
- self[$1] = args.first
+ name_string = name.to_s
+ if name_string.chomp!('=')
+ self[name_string] = args.first
else
self[name]
end