mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-28 04:48:49 +01:00
Using tr is faster than gsub
Using tr is faster than gsub when replacing a single character in a string with another single character. Also freeze constant strings
This commit is contained in:
parent
d3aa73f783
commit
bb006f98c1
1 changed files with 4 additions and 4 deletions
|
|
@ -3,8 +3,8 @@ class Tag < ActiveRecord::Base
|
|||
has_many :taggings
|
||||
has_many :taggable, :through => :taggings
|
||||
|
||||
DELIMITER = "," # Controls how to split and join tagnames from strings. You may need to change the <tt>validates_format_of parameters</tt> if you change this.
|
||||
JOIN_DELIMITER = ", "
|
||||
DELIMITER = ",".freeze # Controls how to split and join tagnames from strings. You may need to change the <tt>validates_format_of parameters</tt> if you change this.
|
||||
JOIN_DELIMITER = ", ".freeze
|
||||
|
||||
# If database speed becomes an issue, you could remove these validations and
|
||||
# rescue the ActiveRecord database constraint errors instead.
|
||||
|
|
@ -17,11 +17,11 @@ class Tag < ActiveRecord::Base
|
|||
# allow tags to be renamed later, you might want to use the
|
||||
# <tt>before_save</tt> callback instead.
|
||||
def before_create
|
||||
self.name = name.downcase.strip.squeeze(" ")
|
||||
self.name = name.downcase.strip.squeeze(' '.freeze)
|
||||
end
|
||||
|
||||
def label
|
||||
@label ||= name.gsub(' ', '-')
|
||||
@label ||= name.tr(' '.freeze, '-'.freeze)
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue