Fix fifo: uniq! is understandably slow.

toying-with-ramdb
Philippe PITTOLI 2024-05-23 12:41:14 +02:00
parent b38e3f31ba
commit 408be2097c
1 changed files with 1 additions and 1 deletions

View File

@ -30,8 +30,8 @@ class FIFO(V)
# NOTE: `#<<(v : V)` is the only function since it's enough for the intended use, feel free to improve this.
# WARNING: implementation is extremely simple (3 lines) and not designed to be highly efficient.
def <<(v : V) : V?
@data.select! { |x| v != v } # remove dups
@data.unshift v # push on top of the stack
@data.uniq! # remove dups
@data.pop if @data.size > @max_entries # remove least recently used entry if `@data` is too big
end
end