From 5aa55903a6c20a0989723bf2f84f8932da3a85e4 Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 12 Feb 2008 06:18:06 +0000 Subject: * ext/json/lib/json/pure/generator.rb, ext/json/lib/json/pure/parser.rb, ext/openssl/lib/openssl/x509.rb, ext/win32ole/sample/olegen.rb, lib/date/format.rb, lib/irb/context.rb, lib/irb/workspace.rb, lib/net/http.rb, lib/net/imap.rb, lib/rdoc/generator.rb, lib/rdoc/markup/to_html.rb, lib/rdoc/markup/to_latex.rb, lib/rdoc/parsers/parse_c.rb, lib/rdoc/ri/formatter.rb, lib/rexml/parsers/baseparser.rb, lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rss/parser.rb, lib/uri/common.rb, lib/uri/generic.rb, lib/webrick/httpresponse.rb, lib/webrick/httpservlet/filehandler.rb, lib/yaml/baseemitter.rb, lib/yaml/encoding.rb: performance tuning arround String#gsub. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/generator.rb | 6 +++--- lib/rdoc/markup/to_html.rb | 6 +++--- lib/rdoc/markup/to_latex.rb | 6 +++--- lib/rdoc/parsers/parse_c.rb | 2 +- lib/rdoc/ri/formatter.rb | 30 +++++++++++++++--------------- 5 files changed, 25 insertions(+), 25 deletions(-) (limited to 'lib/rdoc') diff --git a/lib/rdoc/generator.rb b/lib/rdoc/generator.rb index b62cd0050..0e5b4a8cc 100644 --- a/lib/rdoc/generator.rb +++ b/lib/rdoc/generator.rb @@ -523,7 +523,7 @@ module RDoc::Generator def http_url(full_name, prefix) path = full_name.dup - path.gsub!(/<<\s*(\w*)/) { "from-#$1" } if path['<<'] + path.gsub!(/<<\s*(\w*)/, 'from-\1') if path['<<'] ::File.join(prefix, path.split("::")) + ".html" end @@ -704,8 +704,8 @@ module RDoc::Generator end def filename_to_label - @context.file_relative_name.gsub(/%|\/|\?|\#/) do |s| - '%%%x' % s[0].unpack('C') + @context.file_relative_name.gsub(/%|\/|\?|\#/) do + '%%%x' % $&[0].unpack('C') end end diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index da42312ff..4fe16f8e9 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -200,14 +200,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter gsub(/\.\.\.\./, '.…').gsub(/\.\.\./, '…'). # convert single closing quote - gsub(%r{([^ \t\r\n\[\{\(])\'}) { "#$1’" }. - gsub(%r{\'(?=\W|s\b)}) { "’" }. + gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1’'). + gsub(%r{\'(?=\W|s\b)}, '’'). # convert single opening quote gsub(/'/, '‘'). # convert double closing quote - gsub(%r{([^ \t\r\n\[\{\(])\'(?=\W)}) { "#$1”" }. + gsub(%r{([^ \t\r\n\[\{\(])\'(?=\W)}, '\1”'). # convert double opening quote gsub(/'/, '“'). diff --git a/lib/rdoc/markup/to_latex.rb b/lib/rdoc/markup/to_latex.rb index a679b3b06..bbf958f2e 100644 --- a/lib/rdoc/markup/to_latex.rb +++ b/lib/rdoc/markup/to_latex.rb @@ -227,14 +227,14 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter gsub(/\.\.\.\./, '.\ldots{}').gsub(/\.\.\./, '\ldots{}'). # convert single closing quote - gsub(%r{([^ \t\r\n\[\{\(])\'}) { "#$1'" }. - gsub(%r{\'(?=\W|s\b)}) { "'" }. + gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1\''). + gsub(%r{\'(?=\W|s\b)}, "'" ). # convert single opening quote gsub(/'/, '`'). # convert double closing quote - gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}) { "#$1''" }. + gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}, "\\1''"). # convert double opening quote gsub(/"/, "``"). diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb index 07d65bc9d..5771250cb 100644 --- a/lib/rdoc/parsers/parse_c.rb +++ b/lib/rdoc/parsers/parse_c.rb @@ -766,7 +766,7 @@ module RDoc # Removes #ifdefs that would otherwise confuse us def handle_ifdefs_in(body) - body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m) { $1 } + body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m, '\1') end end diff --git a/lib/rdoc/ri/formatter.rb b/lib/rdoc/ri/formatter.rb index d88cef1e3..df73bf5eb 100644 --- a/lib/rdoc/ri/formatter.rb +++ b/lib/rdoc/ri/formatter.rb @@ -87,22 +87,22 @@ class RDoc::RI::Formatter # Convert HTML entities back to ASCII def conv_html(txt) - txt. - gsub(/>/, '>'). - gsub(/</, '<'). - gsub(/"/, '"'). - gsub(/&/, '&') + txt = txt.gsub(/>/, '>') + txt.gsub!(/</, '<') + txt.gsub!(/"/, '"') + txt.gsub!(/&/, '&') + txt end ## # Convert markup into display form def conv_markup(txt) - txt. - gsub(%r{(.*?)}) { "+#$1+" } . - gsub(%r{(.*?)}) { "+#$1+" } . - gsub(%r{(.*?)}) { "*#$1*" } . - gsub(%r{(.*?)}) { "_#$1_" } + txt = txt.gsub(%r{(.*?)}, '+\1+') + txt.gsub!(%r{(.*?)}, '+\1+') + txt.gsub!(%r{(.*?)}, '*\1*') + txt.gsub!(%r{(.*?)}, '_\1_') + txt end def display_list(list) @@ -548,11 +548,11 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter end def escape(str) - str. - gsub(/&/n, '&'). - gsub(/\"/n, '"'). - gsub(/>/n, '>'). - gsub(//n, '>') + str.gsub!(/