Skip to content

Commit

Permalink
Check for brotli, ezstd, and nimble_csv at compile-time
Browse files Browse the repository at this point in the history
Calling Code.ensure_loaded?/1 at runtime is slow.
  • Loading branch information
wojtekmach committed Oct 5, 2023
1 parent 16e397c commit e0fef9e
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions lib/req/steps.ex
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,11 @@ defmodule Req.Steps do
end

defmacrop brotli_loaded? do
if Code.ensure_loaded?(:brotli) do
true
else
quote do
Code.ensure_loaded?(:brotli)
end
end
Code.ensure_loaded?(:brotli)
end

defmacrop ezstd_loaded? do
if Code.ensure_loaded?(:ezstd) do
true
else
quote do
Code.ensure_loaded?(:ezstd)
end
end
Code.ensure_loaded?(:ezstd)
end

defp supported_accept_encoding do
Expand Down Expand Up @@ -1226,13 +1214,7 @@ defmodule Req.Steps do
end

defmacrop nimble_csv_loaded? do
if Code.ensure_loaded?(NimbleCSV) do
true
else
quote do
Code.ensure_loaded?(NimbleCSV)
end
end
Code.ensure_loaded?(NimbleCSV)
end

@doc false
Expand Down

0 comments on commit e0fef9e

Please sign in to comment.