[ruby/rdoc] Use flat_map for better performance
https://github.com/ruby/rdoc/commit/76192a280d
This commit is contained in:
parent
c2f4b41480
commit
0c55ef1150
@ -610,7 +610,7 @@ class RDoc::Generator::Darkfish
|
|||||||
|
|
||||||
@classes = @store.all_classes_and_modules.sort
|
@classes = @store.all_classes_and_modules.sort
|
||||||
@files = @store.all_files.sort
|
@files = @store.all_files.sort
|
||||||
@methods = @classes.map { |m| m.method_list }.flatten.sort
|
@methods = @classes.flat_map { |m| m.method_list }.sort
|
||||||
@modsort = get_sorted_module_list @classes
|
@modsort = get_sorted_module_list @classes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -230,9 +230,9 @@ class RDoc::Generator::JsonIndex
|
|||||||
def index_methods
|
def index_methods
|
||||||
debug_msg " generating method search index"
|
debug_msg " generating method search index"
|
||||||
|
|
||||||
list = @classes.uniq.map do |klass|
|
list = @classes.uniq.flat_map do |klass|
|
||||||
klass.method_list
|
klass.method_list
|
||||||
end.flatten.sort_by do |method|
|
end.sort_by do |method|
|
||||||
[method.name, method.parent.full_name]
|
[method.name, method.parent.full_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@
|
|||||||
|
|
||||||
<h2 id="methods">Methods</h2>
|
<h2 id="methods">Methods</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<%- @store.all_classes_and_modules.map do |mod|
|
<%- @store.all_classes_and_modules.flat_map do |mod|
|
||||||
mod.method_list
|
mod.method_list
|
||||||
end.flatten.sort.each do |method| %>
|
end.sort.each do |method| %>
|
||||||
<li class="method">
|
<li class="method">
|
||||||
<a href="<%= method.path %>"><%= h method.pretty_name %></a>
|
<a href="<%= method.path %>"><%= h method.pretty_name %></a>
|
||||||
—
|
—
|
||||||
|
@ -25,9 +25,9 @@ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
|
|||||||
def accept_paragraph paragraph
|
def accept_paragraph paragraph
|
||||||
parts = paragraph.parts.chunk do |part|
|
parts = paragraph.parts.chunk do |part|
|
||||||
String === part
|
String === part
|
||||||
end.map do |string, chunk|
|
end.flat_map do |string, chunk|
|
||||||
string ? chunk.join.rstrip : chunk
|
string ? chunk.join.rstrip : chunk
|
||||||
end.flatten
|
end
|
||||||
|
|
||||||
paragraph.parts.replace parts
|
paragraph.parts.replace parts
|
||||||
end
|
end
|
||||||
|
@ -602,9 +602,9 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_accept_verbatim_redefinable_operators
|
def test_accept_verbatim_redefinable_operators
|
||||||
functions = %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].map { |redefinable_op|
|
functions = %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].flat_map { |redefinable_op|
|
||||||
["def #{redefinable_op}\n", "end\n"]
|
["def #{redefinable_op}\n", "end\n"]
|
||||||
}.flatten
|
}
|
||||||
|
|
||||||
verb = @RM::Verbatim.new(*functions)
|
verb = @RM::Verbatim.new(*functions)
|
||||||
|
|
||||||
|
@ -373,9 +373,9 @@ class TestRDocStore < XrefTestCase
|
|||||||
assert_equal [@mod], s.all_modules.sort
|
assert_equal [@mod], s.all_modules.sort
|
||||||
assert_equal [@page, @top_level], s.all_files.sort
|
assert_equal [@page, @top_level], s.all_files.sort
|
||||||
|
|
||||||
methods = s.all_classes_and_modules.map do |mod|
|
methods = s.all_classes_and_modules.flat_map do |mod|
|
||||||
mod.method_list
|
mod.method_list
|
||||||
end.flatten.sort
|
end.sort
|
||||||
|
|
||||||
_meth_bang_alias = RDoc::AnyMethod.new nil, 'method_bang'
|
_meth_bang_alias = RDoc::AnyMethod.new nil, 'method_bang'
|
||||||
_meth_bang_alias.parent = @klass
|
_meth_bang_alias.parent = @klass
|
||||||
@ -388,9 +388,9 @@ class TestRDocStore < XrefTestCase
|
|||||||
|
|
||||||
assert_equal @klass, methods.last.parent
|
assert_equal @klass, methods.last.parent
|
||||||
|
|
||||||
attributes = s.all_classes_and_modules.map do |mod|
|
attributes = s.all_classes_and_modules.flat_map do |mod|
|
||||||
mod.attributes
|
mod.attributes
|
||||||
end.flatten.sort
|
end.sort
|
||||||
|
|
||||||
assert_equal [@attr], attributes
|
assert_equal [@attr], attributes
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user