refactor(ops): rework binary and extra
This commit is contained in:
1 parent
fd5356e789
commit
150a32e952
2 files changed
+9
-15
No files matched your search
@@ -55,6 +55,9 @@ defmodule Excache.Store.Ops.Binary do
|
||||
:wrongtype ->
|
||||
{:error, :wrongtype}
|
||||
|
||||
{:ok, current, _ea, _exists} when value == "" ->
|
||||
{:ok, byte_size(current)}
|
||||
|
||||
{:ok, current, ea, _exists} ->
|
||||
updated = overwrite(current, offset, value)
|
||||
store(table, key, updated, ea)
|
||||
@@ -149,8 +152,6 @@ defmodule Excache.Store.Ops.Binary do
|
||||
end
|
||||
end
|
||||
|
||||
defp overwrite(current, offset, value) when value == "", do: current
|
||||
|
||||
defp overwrite(current, offset, value) do
|
||||
size = byte_size(current)
|
||||
padded = if size < offset, do: current <> :binary.copy(<<0>>, offset - size), else: current
|
||||
|
||||
@@ -313,22 +313,15 @@ defmodule Excache.Store.Ops.Extra do
|
||||
scanned =
|
||||
if rank < 0, do: Enum.reverse(indexed), else: indexed
|
||||
|
||||
skip = abs(rank) - 1
|
||||
limit = if count == 0, do: :all, else: count
|
||||
matches = collectMatches(scanned, element, abs(rank) - 1, matchLimit(count), maxlen, 0, [])
|
||||
|
||||
collectMatches(scanned, element, skip, limit, maxlen, 0, [])
|
||||
|> then(fn matches ->
|
||||
if count == nil do
|
||||
case matches do
|
||||
[] -> nil
|
||||
[first | _] -> first
|
||||
end
|
||||
else
|
||||
matches
|
||||
end
|
||||
end)
|
||||
if count == nil, do: List.first(matches), else: matches
|
||||
end
|
||||
|
||||
defp matchLimit(nil), do: 1
|
||||
defp matchLimit(0), do: :all
|
||||
defp matchLimit(count), do: count
|
||||
|
||||
defp collectMatches([], _element, _skip, _limit, _maxlen, _compared, acc),
|
||||
do: Enum.reverse(acc)
|
||||
|
||||
|
||||
Reference in new issue
Block a user