Permalink
Browse files

Improved performance by relying less on exception raising #8159 [Blaine]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@6571 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 67465f8 commit f5977b205feeceee9ac660d7f503b9d19c70957d @dhh dhh committed Apr 24, 2007
View
@@ -4,6 +4,8 @@
* SQLite: binary escaping works with $KCODE='u'. #7862 [tsuka]
+* Improved cloning performance by relying less on exception raising #8159 [Blaine]
+
*1.15.3* (March 12th, 2007)
@@ -2159,7 +2159,13 @@ def clone_attributes(reader_method = :read_attribute, attributes = {})
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
View
@@ -2,6 +2,8 @@
* Update Dependencies to ignore constants inherited from ancestors. Closes #6951. [Nicholas Seckar]
+* Improved multibyte performance by relying less on exception raising #8159 [Blaine]
+
*1.4.2* (March 12th, 2007)
@@ -43,7 +43,7 @@ def to_str
# 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 @@ def =~(other)
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 @@ def utf8_pragma?
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8HandlerProc
rescue LoadError
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8Handler
-end
+end

0 comments on commit f5977b2

Please sign in to comment.