diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-12-26 14:45:57 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2021-09-10 20:00:06 +0900 |
commit | ef7448359478a04d67a4a406cca1c8442b5e2f94 (patch) | |
tree | dbe2a89f17656c431ce51220a35a6f77cf8cb1a3 /tool/strip-rdoc.rb | |
parent | 94e5953b484517234ad476b1e179d1bdbcbafbd7 (diff) | |
download | ruby-ef7448359478a04d67a4a406cca1c8442b5e2f94.tar.gz |
tool/strip-rdoc.rb: optimize
This script is called from Doxygen many times. Worth optimising.
[ci skip]
Diffstat (limited to 'tool/strip-rdoc.rb')
-rwxr-xr-x | tool/strip-rdoc.rb | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/tool/strip-rdoc.rb b/tool/strip-rdoc.rb index 0ac9c39323..d8e311cdbf 100755 --- a/tool/strip-rdoc.rb +++ b/tool/strip-rdoc.rb @@ -1,26 +1,14 @@ #!ruby +# frozen_string_literal: true # Filter for preventing Doxygen from processing RDoc comments. # Used by the Doxygen template. -ARGF.binmode -source = ARGF.read -source = source.gsub(%r{/\*([!*])((?!\*/).+?)\*/}m) do |comment| - marker, comment = $1, $2 - next "/**#{comment}*/" unless /^\s*\*\s?\-\-\s*$/ =~ comment - doxybody = nil - comment.each_line do |line| - if doxybody - if /^\s*\*\s?\+\+\s*$/ =~ line - break - end - doxybody << line - else - if /^\s*\*\s?--\s*$/ =~ line - doxybody = "\n" - end - end - end - "/*#{marker}#{doxybody}*/" -end -print source +print ARGF.binmode.read.tap {|src| + src.gsub!(%r|(/\*[!*])(?:(?!\*/).)+?^\s*\*\s?\-\-\s*$(.+?\*/)|m) { + marker = $1 + comment = $2 + comment.sub!(%r|^\s*\*\s?\+\+\s*$.+?(\s*\*/)\z|m, '\\1') + marker + comment + } +} |