Added resize operation to RingBuffer and make IrcState use it.

This commit is contained in:
Jeremy Fincher 2004-07-21 05:05:16 +00:00
parent 8282d3e847
commit a95f1bc28c
2 changed files with 12 additions and 5 deletions

View File

@ -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()

View File

@ -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: