Skip to content

Commit

Permalink
Use a split instead of 2 reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
bchamagne committed Jun 13, 2023
1 parent ea6a53d commit 277efe3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/archethic_cache/lru.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ defmodule ArchethicCache.LRU do
if predicate.(state) do
state
else
case Enum.reverse(keys) do
[] ->
case Enum.split(keys, -1) do
{[], []} ->
state

[oldest_key | rest] ->
{rest, [oldest_key]} ->
[{_, {size, oldest_value}}] = :ets.take(table, oldest_key)
evict_fn.(oldest_key, oldest_value)

evict_until(
%{
state
| bytes_used: bytes_used - size,
keys: Enum.reverse(rest)
keys: rest
},
predicate
)
Expand Down

0 comments on commit 277efe3

Please sign in to comment.