Skip to content

Commit 76192a2

Browse files
p8hsbt
authored andcommitted
Use flat_map for better performance
1 parent 7135236 commit 76192a2

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

lib/rdoc/generator/darkfish.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def setup
610610

611611
@classes = @store.all_classes_and_modules.sort
612612
@files = @store.all_files.sort
613-
@methods = @classes.map { |m| m.method_list }.flatten.sort
613+
@methods = @classes.flat_map { |m| m.method_list }.sort
614614
@modsort = get_sorted_module_list @classes
615615
end
616616

lib/rdoc/generator/json_index.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ def index_classes
230230
def index_methods
231231
debug_msg " generating method search index"
232232

233-
list = @classes.uniq.map do |klass|
233+
list = @classes.uniq.flat_map do |klass|
234234
klass.method_list
235-
end.flatten.sort_by do |method|
235+
end.sort_by do |method|
236236
[method.name, method.parent.full_name]
237237
end
238238

lib/rdoc/generator/template/darkfish/table_of_contents.rhtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747

4848
<h2 id="methods">Methods</h2>
4949
<ul>
50-
<%- @store.all_classes_and_modules.map do |mod|
50+
<%- @store.all_classes_and_modules.flat_map do |mod|
5151
mod.method_list
52-
end.flatten.sort.each do |method| %>
52+
end.sort.each do |method| %>
5353
<li class="method">
5454
<a href="<%= method.path %>"><%= h method.pretty_name %></a>
5555
&mdash;

lib/rdoc/markup/to_joined_paragraph.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def end_accepting # :nodoc:
2525
def accept_paragraph paragraph
2626
parts = paragraph.parts.chunk do |part|
2727
String === part
28-
end.map do |string, chunk|
28+
end.flat_map do |string, chunk|
2929
string ? chunk.join.rstrip : chunk
30-
end.flatten
30+
end
3131

3232
paragraph.parts.replace parts
3333
end

test/rdoc/test_rdoc_markup_to_html.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,9 @@ def test_accept_verbatim_ruby
602602
end
603603

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

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

test/rdoc/test_rdoc_store.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ def test_load_all
373373
assert_equal [@mod], s.all_modules.sort
374374
assert_equal [@page, @top_level], s.all_files.sort
375375

376-
methods = s.all_classes_and_modules.map do |mod|
376+
methods = s.all_classes_and_modules.flat_map do |mod|
377377
mod.method_list
378-
end.flatten.sort
378+
end.sort
379379

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

389389
assert_equal @klass, methods.last.parent
390390

391-
attributes = s.all_classes_and_modules.map do |mod|
391+
attributes = s.all_classes_and_modules.flat_map do |mod|
392392
mod.attributes
393-
end.flatten.sort
393+
end.sort
394394

395395
assert_equal [@attr], attributes
396396

0 commit comments

Comments
 (0)