Fix fifo: uniq! is understandably slow.

This commit is contained in:
Philippe PITTOLI 2024-05-23 12:41:14 +02:00
parent b38e3f31ba
commit 408be2097c

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