mirror of
https://github.com/github/rails.git
synced 2026-01-10 07:08:08 -05:00
Merge pull request #66 from github/3-0-github-perf
Bring a few perf patches to 3-0-github from 2-3-github
This commit is contained in:
@@ -28,17 +28,28 @@ module ActionView
|
||||
module Handlers
|
||||
class Erubis < ::Erubis::Eruby
|
||||
def add_preamble(src)
|
||||
@newline_pending = 0
|
||||
src << "@output_buffer = ActionView::OutputBuffer.new;"
|
||||
end
|
||||
|
||||
def add_text(src, text)
|
||||
return if text.empty?
|
||||
src << "@output_buffer.safe_concat('" << escape_text(text) << "');"
|
||||
if text == "\n"
|
||||
@newline_pending += 1
|
||||
else
|
||||
src << "@output_buffer.safe_concat('"
|
||||
src << "\n" * @newline_pending
|
||||
src << escape_text(text)
|
||||
src << "'.freeze);"
|
||||
@newline_pending = 0
|
||||
end
|
||||
end
|
||||
|
||||
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
||||
|
||||
def add_expr_literal(src, code)
|
||||
flush_newline_if_pending(src)
|
||||
|
||||
if code =~ BLOCK_EXPR
|
||||
src << '@output_buffer.append= ' << code
|
||||
else
|
||||
@@ -47,6 +58,8 @@ module ActionView
|
||||
end
|
||||
|
||||
def add_stmt(src, code)
|
||||
flush_newline_if_pending(src)
|
||||
|
||||
if code =~ BLOCK_EXPR
|
||||
src << '@output_buffer.append_if_string= ' << code
|
||||
else
|
||||
@@ -55,6 +68,8 @@ module ActionView
|
||||
end
|
||||
|
||||
def add_expr_escaped(src, code)
|
||||
flush_newline_if_pending(src)
|
||||
|
||||
if code =~ BLOCK_EXPR
|
||||
src << "@output_buffer.safe_append= " << code
|
||||
else
|
||||
@@ -63,8 +78,19 @@ module ActionView
|
||||
end
|
||||
|
||||
def add_postamble(src)
|
||||
flush_newline_if_pending(src)
|
||||
|
||||
src << '@output_buffer.to_s'
|
||||
end
|
||||
|
||||
def flush_newline_if_pending(src)
|
||||
if @newline_pending > 0
|
||||
src << "@output_buffer.safe_concat('"
|
||||
src << "\n" * @newline_pending
|
||||
src << "'.freeze);"
|
||||
@newline_pending = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ERB < Handler
|
||||
|
||||
@@ -65,7 +65,8 @@ end
|
||||
|
||||
class String #:nodoc:
|
||||
def blank?
|
||||
self !~ /\S/
|
||||
return true if empty?
|
||||
self =~ /\A\s*\z/
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ module ActiveSupport #:nodoc:
|
||||
def [](*args)
|
||||
return super if args.size < 2
|
||||
|
||||
if html_safe?
|
||||
if @html_safe
|
||||
new_safe_buffer = super
|
||||
new_safe_buffer.instance_eval { @html_safe = true }
|
||||
new_safe_buffer
|
||||
@@ -109,7 +109,7 @@ module ActiveSupport #:nodoc:
|
||||
end
|
||||
|
||||
def safe_concat(value)
|
||||
raise SafeConcatError unless html_safe?
|
||||
raise SafeConcatError unless @html_safe
|
||||
original_concat(value)
|
||||
end
|
||||
|
||||
@@ -128,7 +128,7 @@ module ActiveSupport #:nodoc:
|
||||
end
|
||||
|
||||
def concat(value)
|
||||
if !html_safe? || value.html_safe?
|
||||
if !@html_safe || value.html_safe?
|
||||
super(value)
|
||||
else
|
||||
super(ERB::Util.h(value))
|
||||
|
||||
Reference in New Issue
Block a user