0
0
Fork 0

Improve performance by avoiding regex construction (#20215)

```ruby
10.times { p /#{FOO}/.object_id }
10.times { p FOO_RE.object_id }
```
This commit is contained in:
James Tucker 2022-11-09 20:49:30 -08:00 committed by GitHub
parent 0cd0786aef
commit 78a6b871fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 12 deletions

View file

@ -24,7 +24,7 @@ class Api::V1::TagsController < Api::BaseController
private
def set_or_create_tag
return not_found unless /\A(#{Tag::HASHTAG_NAME_RE})\z/.match?(params[:id])
return not_found unless Tag::HASHTAG_NAME_RE.match?(params[:id])
@tag = Tag.find_normalized(params[:id]) || Tag.new(name: Tag.normalize(params[:id]), display_name: params[:id])
end
end