mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Significantly optimize regexp time of fix_textareas!
The leading whitespace match and back reference added significant overhead in certain cases, sometimes leading to render times taking minutes. In some cases, the render time dropped from 2+ minutes to 200 milliseconds. Closes #849
This commit is contained in:
parent
c89da381a0
commit
bc2b9f186f
1 changed files with 4 additions and 4 deletions
|
@ -273,16 +273,16 @@ module Haml
|
||||||
# @since Haml 4.0.1
|
# @since Haml 4.0.1
|
||||||
# @private
|
# @private
|
||||||
def fix_textareas!(input)
|
def fix_textareas!(input)
|
||||||
pattern = /([ ]*)<(textarea)([^>]*)>(\n|
)(.*?)(<\/\2>)/im
|
pattern = /<(textarea)([^>]*)>(\n|
)(.*?)<\/textarea>/im
|
||||||
input.gsub!(pattern) do |s|
|
input.gsub!(pattern) do |s|
|
||||||
match = pattern.match(s)
|
match = pattern.match(s)
|
||||||
content = match[5]
|
content = match[4]
|
||||||
if match[4] == '
'
|
if match[3] == '
'
|
||||||
content.sub!(/\A /, ' ')
|
content.sub!(/\A /, ' ')
|
||||||
else
|
else
|
||||||
content.sub!(/\A[ ]*/, '')
|
content.sub!(/\A[ ]*/, '')
|
||||||
end
|
end
|
||||||
"#{match[1]}<#{match[2]}#{match[3]}>\n#{content}</#{match[2]}>"
|
"<#{match[1]}#{match[2]}>\n#{content}</#{match[1]}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue