From b8c6c0845218fe976a3f530688c54f62813cb31a Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 15 Nov 2013 00:38:22 -0200 Subject: [PATCH] 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 --- activemodel/lib/active_model/validations/format.rb | 4 ++-- 1 file 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)