Permalink
Browse files

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
  • Loading branch information...
1 parent 70161ae commit b8c6c0845218fe976a3f530688c54f62813cb31a @carlosantoniodasilva carlosantoniodasilva committed Nov 15, 2013
Showing with 2 additions and 2 deletions.
  1. +2 −2 activemodel/lib/active_model/validations/format.rb
View
4 activemodel/lib/active_model/validations/format.rb
@@ -33,8 +33,8 @@ def record_error(record, attribute, name, value)
end
def regexp_using_multiline_anchors?(regexp)
- regexp.source.start_with?("^") ||
- (regexp.source.end_with?("$") && !regexp.source.end_with?("\\$"))
+ source = regexp.source
+ source.start_with?("^") || (source.end_with?("$") && !source.end_with?("\\$"))
end
def check_options_validity(options, name)

0 comments on commit b8c6c08

Please sign in to comment.