diff options
author | brainopia <brainopia@evilmartians.com> | 2015-04-02 01:53:49 +0300 |
---|---|---|
committer | brainopia <brainopia@evilmartians.com> | 2015-04-02 02:07:45 +0300 |
commit | cdac52e124769909b6cb5fce2c4d00e09d21e059 (patch) | |
tree | ec495f33893beb08670daf2ce70696e3171e847b /actionpack/lib/action_controller | |
parent | 4ba1376c608cc797c80402a73568744b1c855f67 (diff) | |
download | rails-cdac52e124769909b6cb5fce2c4d00e09d21e059.tar.gz rails-cdac52e124769909b6cb5fce2c4d00e09d21e059.tar.bz2 rails-cdac52e124769909b6cb5fce2c4d00e09d21e059.zip |
Prefer string patterns for gsub
https://github.com/ruby/ruby/pull/579 - there is a new optimization
since ruby 2.2
Previously regexp patterns were faster (since a string was converted to
regexp underneath anyway). But now string patterns are faster and
better reflect the purpose.
Benchmark.ips do |bm|
bm.report('regexp') { 'this is ::a random string'.gsub(/::/, '/') }
bm.report('string') { 'this is ::a random string'.gsub('::', '/') }
bm.compare!
end
# string: 753724.4 i/s
# regexp: 501443.1 i/s - 1.50x slower
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/metal/http_authentication.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/live.rb | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 2273406948..a2e5452063 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -118,7 +118,7 @@ module ActionController end def authentication_request(controller, realm) - controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}") + controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub('"', "")}") controller.status = 401 controller.response_body = "HTTP Basic: Access denied.\n" end @@ -499,7 +499,7 @@ module ActionController # # Returns nothing. def authentication_request(controller, realm) - controller.headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub(/"/, "")}") + controller.headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub('"', "")}") controller.__send__ :render, :text => "HTTP Token: Access denied.\n", :status => :unauthorized end end diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb index 7590fb6843..8fa06d43ff 100644 --- a/actionpack/lib/action_controller/metal/live.rb +++ b/actionpack/lib/action_controller/metal/live.rb @@ -102,7 +102,7 @@ module ActionController end end - message = json.gsub(/\n/, "\ndata: ") + message = json.gsub("\n", "\ndata: ") @stream.write "data: #{message}\n\n" end end |