diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2007-09-10 07:23:59 +0000 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2007-09-10 07:23:59 +0000 |
commit | 5cdc7a11e351e6322fb1a4eb01532e49cdb7c804 (patch) | |
tree | 8ee5b319d4a50d36bfdf33ceb7ee1b320b47b5d6 /lib/erubis/enhancer.rb | |
parent | 204983a9e68b4d0be44842a4f98fc36d1aced035 (diff) | |
download | erubis-5cdc7a11e351e6322fb1a4eb01532e49cdb7c804.tar.gz |
- [bugfix] PercentLineEnhancer#add_text() was very slow (now very fast)
Diffstat (limited to 'lib/erubis/enhancer.rb')
-rw-r--r-- | lib/erubis/enhancer.rb | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb index 3b61975..b129a11 100644 --- a/lib/erubis/enhancer.rb +++ b/lib/erubis/enhancer.rb @@ -443,18 +443,33 @@ module Erubis "regard lines starting with '%' as program code" end - PERCENT_LINE_PATTERN = /(.*?)^\%(.*?\r?\n)/m - def add_text(src, text) - text.scan(PERCENT_LINE_PATTERN) do |txt, line| - super(src, txt) + pos = 0 + text2 = '' + text.scan(/^\%(.*?\r?\n)/) do + line = $1 + match = Regexp.last_match + len = match.begin(0) - pos + str = text[pos, len] + pos = match.end(0) + if text2.empty? + text2 = str + else + text2 << str + end if line[0] == ?% - super(src, line) + text2 << line else + super(src, text2) + text2 = '' add_stmt(src, line) end end - rest = $' || text + rest = pos == 0 ? text : $' # or $' || text + unless text2.empty? + text2 << rest if rest + rest = text2 + end super(src, rest) end |