Permalink
Browse files

Simplify and improve the performance of output_safety

  • Loading branch information...
1 parent f3b0721 commit 3b1642c23cb433dde3d96f0b70dfdc66d15f6713 Yehuda Katz committed Dec 25, 2009
Showing with 6 additions and 22 deletions.
  1. +6 −22 activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -1,7 +1,6 @@
class String
- def html_safe?
- defined?(@_rails_html_safe) && @_rails_html_safe
- end
+ attr_accessor :_rails_html_safe
+ alias html_safe? _rails_html_safe
def html_safe!
@_rails_html_safe = true
@@ -15,31 +14,16 @@ def html_safe
alias original_plus +
def +(other)
result = original_plus(other)
- if html_safe? && also_html_safe?(other)
- result.html_safe!
- else
- result
- end
+ result._rails_html_safe = html_safe? && other.html_safe?
+ result
end
alias original_concat <<
alias safe_concat <<
def <<(other)
+ @_rails_html_safe = false unless other.html_safe?
result = original_concat(other)
- unless html_safe? && also_html_safe?(other)
- @_rails_html_safe = false
- end
- result
end
- remove_method :concat
- def concat(other)
- self << other
- end
-
- private
- def also_html_safe?(other)
- other.respond_to?(:html_safe?) && other.html_safe?
- end
-
+ alias concat <<
end

0 comments on commit 3b1642c

Please sign in to comment.