Skip to content

Commit

Permalink
[ruby/rdoc] Use flat_map for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
p8 authored and matzbot committed Jun 14, 2023
1 parent c2f4b41 commit 0c55ef1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/rdoc/generator/darkfish.rb
Expand Up @@ -610,7 +610,7 @@ def setup

@classes = @store.all_classes_and_modules.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
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/generator/json_index.rb
Expand Up @@ -230,9 +230,9 @@ def index_classes
def index_methods
debug_msg " generating method search index"

list = @classes.uniq.map do |klass|
list = @classes.uniq.flat_map do |klass|
klass.method_list
end.flatten.sort_by do |method|
end.sort_by do |method|
[method.name, method.parent.full_name]
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/generator/template/darkfish/table_of_contents.rhtml
Expand Up @@ -47,9 +47,9 @@

<h2 id="methods">Methods</h2>
<ul>
<%- @store.all_classes_and_modules.map do |mod|
<%- @store.all_classes_and_modules.flat_map do |mod|
mod.method_list
end.flatten.sort.each do |method| %>
end.sort.each do |method| %>
<li class="method">
<a href="<%= method.path %>"><%= h method.pretty_name %></a>
&mdash;
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/markup/to_joined_paragraph.rb
Expand Up @@ -25,9 +25,9 @@ def end_accepting # :nodoc:
def accept_paragraph paragraph
parts = paragraph.parts.chunk do |part|
String === part
end.map do |string, chunk|
end.flat_map do |string, chunk|
string ? chunk.join.rstrip : chunk
end.flatten
end

paragraph.parts.replace parts
end
Expand Down
4 changes: 2 additions & 2 deletions test/rdoc/test_rdoc_markup_to_html.rb
Expand Up @@ -602,9 +602,9 @@ def test_accept_verbatim_ruby
end

def test_accept_verbatim_redefinable_operators
functions = %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].map { |redefinable_op|
functions = %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].flat_map { |redefinable_op|
["def #{redefinable_op}\n", "end\n"]
}.flatten
}

verb = @RM::Verbatim.new(*functions)

Expand Down
8 changes: 4 additions & 4 deletions test/rdoc/test_rdoc_store.rb
Expand Up @@ -373,9 +373,9 @@ def test_load_all
assert_equal [@mod], s.all_modules.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
end.flatten.sort
end.sort

_meth_bang_alias = RDoc::AnyMethod.new nil, 'method_bang'
_meth_bang_alias.parent = @klass
Expand All @@ -388,9 +388,9 @@ def test_load_all

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
end.flatten.sort
end.sort

assert_equal [@attr], attributes

Expand Down

0 comments on commit 0c55ef1

Please sign in to comment.