mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Added resize operation to RingBuffer and make IrcState use it.
This commit is contained in:
parent
8282d3e847
commit
a95f1bc28c
@ -275,6 +275,7 @@ class IrcState(IrcCommandDispatcher):
|
||||
def reset(self):
|
||||
"""Resets the state to normal, unconnected state."""
|
||||
self.history.reset()
|
||||
self.history.resize(conf.supybot.protocols.irc.maxHistoryLength())
|
||||
self.channels = ircutils.IrcDict()
|
||||
self.nicksToHostmasks = ircutils.IrcDict()
|
||||
|
||||
|
@ -60,6 +60,13 @@ class RingBuffer(object):
|
||||
self.L = []
|
||||
self.i = 0
|
||||
|
||||
def resize(self, i):
|
||||
if self.full:
|
||||
L = list(self)
|
||||
self.reset()
|
||||
self.L = L
|
||||
self.maxSize = i
|
||||
|
||||
def __len__(self):
|
||||
return len(self.L)
|
||||
|
||||
@ -85,12 +92,11 @@ class RingBuffer(object):
|
||||
self.L[self.i] = elt
|
||||
self.i += 1
|
||||
self.i %= len(self.L)
|
||||
elif len(self) == self.maxSize:
|
||||
self.full = True
|
||||
self.append(elt)
|
||||
else:
|
||||
if len(self) >= self.maxSize:
|
||||
self.full = True
|
||||
self.append(elt)
|
||||
else:
|
||||
self.L.append(elt)
|
||||
self.L.append(elt)
|
||||
|
||||
def extend(self, seq):
|
||||
for elt in seq:
|
||||
|
Loading…
Reference in New Issue
Block a user