Browse files

Instead of marking raw text in templates as safe, and then putting th…

…em through String#<< which checks if the String is safe, use safe_concat, which uses the original (internal) String#<< and leaves the safe flag as is. Results in a significant performance improvement.
  • Loading branch information...
1 parent baaaf2a commit f3b072189a6a77717f99e38403392a68f5818a49 Yehuda Katz committed Dec 24, 2009
3 actionpack/lib/action_view/template/handlers/erb.rb
@@ -10,7 +10,8 @@ def add_preamble(src)
def add_text(src, text)
- src << "@output_buffer << ('" << escape_text(text) << "'.html_safe!);"
+ return if text.empty?
+ src << "@output_buffer.safe_concat('" << escape_text(text) << "');"
def add_expr_literal(src, code)
1 activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -23,6 +23,7 @@ def +(other)
alias original_concat <<
+ alias safe_concat <<
def <<(other)
result = original_concat(other)
unless html_safe? && also_html_safe?(other)

2 comments on commit f3b0721


Argh. I saw this coming, reimplemented the String safety stuff to avoid it, but never got around to doing the other 80%: writing the patch and posting it. Now It's too late.



Please sign in to comment.