aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-04-24 16:58:24 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-04-24 16:58:24 +0000
commit57352f86d43f6d3ee30f07d795087e68bf07f521 (patch)
tree983428b4d96cbb0988858080ee6537235f2970bd
parentb3c4e301f490be57677aa3137329522e572b1d0f (diff)
downloadrails-57352f86d43f6d3ee30f07d795087e68bf07f521.tar.gz
rails-57352f86d43f6d3ee30f07d795087e68bf07f521.tar.bz2
rails-57352f86d43f6d3ee30f07d795087e68bf07f521.zip
Improved performance by relying less on exception raising #8159 [Blaine]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6571 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb12
4 files changed, 17 insertions, 7 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index b6d009bbb0..da7572149c 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Improved cloning performance by relying less on exception raising #8159 [Blaine]
+
* Added ActiveRecord::Base.inspect to return a column-view like #<Post id:integer, title:string, body:text> [DHH]
* Added yielding of Builder instance for ActiveRecord::Base#to_xml calls [DHH]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index c46e97b1b7..d1e70ce04d 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2231,7 +2231,13 @@ module ActiveRecord #:nodoc:
def clone_attribute_value(reader_method, attribute_name)
value = send(reader_method, attribute_name)
- value.clone
+
+ case value
+ when nil, Fixnum, true, false
+ value
+ else
+ value.clone
+ end
rescue TypeError, NoMethodError
value
end
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index bfac524d95..ea734dcddf 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Improved multibyte performance by relying less on exception raising #8159 [Blaine]
+
* Use XSD-compatible type names for Hash#to_xml and make the converters extendable #8047 [Tim Pope]
* Added yielding of builder in Hash#to_xml [DHH]
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index 374adc7849..901815092d 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -43,7 +43,7 @@ module ActiveSupport::Multibyte #:nodoc:
# Create a new Chars instance.
def initialize(str)
- @string = (str.string rescue str)
+ @string = str.respond_to?(:string) ? str.string : str
end
# Returns -1, 0 or +1 depending on whether the Chars object is to be sorted before, equal or after the
@@ -70,18 +70,18 @@ module ActiveSupport::Multibyte #:nodoc:
def method_missing(m, *a, &b)
begin
# Simulate methods with a ! at the end because we can't touch the enclosed string from the handlers.
- if m.to_s =~ /^(.*)\!$/
+ if m.to_s =~ /^(.*)\!$/ && handler.respond_to?($1)
result = handler.send($1, @string, *a, &b)
if result == @string
result = nil
else
@string.replace result
end
- else
+ elsif handler.respond_to?(m)
result = handler.send(m, @string, *a, &b)
+ else
+ result = @string.send(m, *a, &b)
end
- rescue NoMethodError
- result = @string.send(m, *a, &b)
rescue Handlers::EncodingError
@string.replace handler.tidy_bytes(@string)
retry
@@ -126,4 +126,4 @@ begin
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8HandlerProc
rescue LoadError
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8Handler
-end \ No newline at end of file
+end