refactor(ops): rework binary and extra

This commit is contained in:
dualfroz committed 2026-09-08 20:28:41 +02:00
1 parent fd5356e789
commit 150a32e952
2 files changed
+9 -15

No files matched your search

+3 -2
View File
@@ -55,6 +55,9 @@ defmodule Excache.Store.Ops.Binary do
:wrongtype -> :wrongtype ->
{:error, :wrongtype} {:error, :wrongtype}
{:ok, current, _ea, _exists} when value == "" ->
{:ok, byte_size(current)}
{:ok, current, ea, _exists} -> {:ok, current, ea, _exists} ->
updated = overwrite(current, offset, value) updated = overwrite(current, offset, value)
store(table, key, updated, ea) store(table, key, updated, ea)
@@ -149,8 +152,6 @@ defmodule Excache.Store.Ops.Binary do
end end
end end
defp overwrite(current, offset, value) when value == "", do: current
defp overwrite(current, offset, value) do defp overwrite(current, offset, value) do
size = byte_size(current) size = byte_size(current)
padded = if size < offset, do: current <> :binary.copy(<<0>>, offset - size), else: current padded = if size < offset, do: current <> :binary.copy(<<0>>, offset - size), else: current
+6 -13
View File
@@ -313,22 +313,15 @@ defmodule Excache.Store.Ops.Extra do
scanned = scanned =
if rank < 0, do: Enum.reverse(indexed), else: indexed if rank < 0, do: Enum.reverse(indexed), else: indexed
skip = abs(rank) - 1 matches = collectMatches(scanned, element, abs(rank) - 1, matchLimit(count), maxlen, 0, [])
limit = if count == 0, do: :all, else: count
collectMatches(scanned, element, skip, limit, maxlen, 0, []) if count == nil, do: List.first(matches), else: matches
|> then(fn matches ->
if count == nil do
case matches do
[] -> nil
[first | _] -> first
end
else
matches
end
end)
end end
defp matchLimit(nil), do: 1
defp matchLimit(0), do: :all
defp matchLimit(count), do: count
defp collectMatches([], _element, _skip, _limit, _maxlen, _compared, acc), defp collectMatches([], _element, _skip, _limit, _maxlen, _compared, acc),
do: Enum.reverse(acc) do: Enum.reverse(acc)