Skip to content

Commit

Permalink
Minor iteration optimizations (elixir-lsp#527)
Browse files Browse the repository at this point in the history
* perf: Remove iteration with Enum.map_join/3

* perf: Remove another iteration with Enum.map_join/3

* perf: Remove iteration using Map.new/2
  • Loading branch information
asummers authored and vanjabucic committed Jul 5, 2021
1 parent bb57268 commit 99a883e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions apps/language_server/lib/language_server/diagnostics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
if stacktrace != [] do
stacktrace =
stacktrace
|> Enum.map(&" │ #{&1}")
|> Enum.join("\n")
|> Enum.map_join("\n", &" │ #{&1}")
|> String.trim_trailing()

description <> "\n\n" <> "Stacktrace:\n" <> stacktrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ApplySpec do
Code.format_string!("@spec #{spec}", line_length: target_line_length)
|> IO.iodata_to_binary()
|> SourceFile.lines()
|> Enum.map(&(indentation <> &1))
|> Enum.join("\n")
|> Enum.map_join("\n", &(indentation <> &1))
|> Kernel.<>("\n")
rescue
_ ->
Expand Down
3 changes: 1 addition & 2 deletions apps/language_server/test/source_file_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ defmodule ElixirLS.LanguageServer.SourceFileTest do
|> elem(0)
|> Enum.reverse()
|> Enum.with_index()
|> Enum.map(fn {off, ind} -> {ind, off} end)
|> Enum.into(%{})
|> Map.new(fn {off, ind} -> {ind, off} end)
end

defp find_low_high(low, high, offset, line_offsets) when low < high do
Expand Down

0 comments on commit 99a883e

Please sign in to comment.