Fix fifo: uniq! is understandably slow.
parent
b38e3f31ba
commit
408be2097c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue