From fc14fc26723e725bded8497a47d38ba6eca7fe4a Mon Sep 17 00:00:00 2001 From: Jakub Jasiulewicz Date: Fri, 5 Apr 2024 08:34:12 +0200 Subject: [PATCH] Optimize checking actor gate --- lib/fun_with_flags/flag.ex | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/fun_with_flags/flag.ex b/lib/fun_with_flags/flag.ex index 51afc7c6..61d0c449 100644 --- a/lib/fun_with_flags/flag.ex +++ b/lib/fun_with_flags/flag.ex @@ -59,20 +59,24 @@ defmodule FunWithFlags.Flag do defp check_actor_gates(gates, item) do gates - |> actor_gates() |> do_check_actor_gates(item) end + defp do_check_actor_gates([], _), do: :ignore - - defp do_check_actor_gates([gate|rest], item) do + + defp do_check_actor_gates([%Gate{type: :actor} = gate | rest], item) do case Gate.enabled?(gate, for: item) do :ignore -> do_check_actor_gates(rest, item) - result -> result + result -> result end end + + defp do_check_actor_gates([_gate | rest], item) do + do_check_actor_gates(rest, item) + end - + defp check_group_gates(gates, item) do gates |> group_gates() @@ -133,10 +137,6 @@ defmodule FunWithFlags.Flag do Enum.find(gates, &Gate.boolean?/1) end - defp actor_gates(gates) do - Enum.filter(gates, &Gate.actor?/1) - end - defp group_gates(gates) do Enum.filter(gates, &Gate.group?/1) end