1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Cache regexp source on format validation to avoid allocating new objects

Example:

    >> r = /some-regexp/
    => /some-regexp/
    >> r.source.object_id == r.source.object_id
    => false
This commit is contained in:
Carlos Antonio da Silva 2013-11-15 00:38:22 -02:00
parent 70161ae3b8
commit b8c6c08452

View file

@ -33,8 +33,8 @@ module ActiveModel
end end
def regexp_using_multiline_anchors?(regexp) def regexp_using_multiline_anchors?(regexp)
regexp.source.start_with?("^") || source = regexp.source
(regexp.source.end_with?("$") && !regexp.source.end_with?("\\$")) source.start_with?("^") || (source.end_with?("$") && !source.end_with?("\\$"))
end end
def check_options_validity(options, name) def check_options_validity(options, name)