From e0fef9ee9de83087091ddecfc1fc670d2c97b63f Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Thu, 5 Oct 2023 23:36:56 +0200 Subject: [PATCH] Check for brotli, ezstd, and nimble_csv at compile-time Calling Code.ensure_loaded?/1 at runtime is slow. --- lib/req/steps.ex | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/lib/req/steps.ex b/lib/req/steps.ex index f8802e64..78e14f31 100644 --- a/lib/req/steps.ex +++ b/lib/req/steps.ex @@ -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 @@ -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