diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-15 00:38:22 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-15 00:38:55 -0200 |
commit | b8c6c0845218fe976a3f530688c54f62813cb31a (patch) | |
tree | a70b3d1145f9bfb49e3bb67288670e9206624694 | |
parent | 70161ae3b890bb6b0603470709432a1bec911da7 (diff) | |
download | rails-b8c6c0845218fe976a3f530688c54f62813cb31a.tar.gz rails-b8c6c0845218fe976a3f530688c54f62813cb31a.tar.bz2 rails-b8c6c0845218fe976a3f530688c54f62813cb31a.zip |
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
-rw-r--r-- | activemodel/lib/active_model/validations/format.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb index be7cae588f..b6cc162582 100644 --- a/activemodel/lib/active_model/validations/format.rb +++ b/activemodel/lib/active_model/validations/format.rb @@ -33,8 +33,8 @@ module ActiveModel 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) |