Use an array for line offset mapping (if file < 4GB)

This commit is contained in:
René Stadler 2007-11-21 11:40:13 +02:00 committed by Stefan Sauer
parent 03713f4a0e
commit 75d1ff49e4

View file

@ -169,9 +169,6 @@ class LineCache (Producer):
Producer.__init__ (self) Producer.__init__ (self)
self.logger = logging.getLogger ("linecache") self.logger = logging.getLogger ("linecache")
self.offsets = []
self.levels = [] # FIXME
self.dispatcher = dispatcher self.dispatcher = dispatcher
import mmap import mmap
@ -181,6 +178,18 @@ class LineCache (Producer):
self.__file_size = self.__fileobj.tell () self.__file_size = self.__fileobj.tell ()
self.__fileobj.seek (0) self.__fileobj.seek (0)
from array import array
offsets = array ("L")
try:
offsets.append (self.__file_size)
except OverflowError:
offsets = []
else:
del offsets[0]
self.offsets = offsets
self.levels = [] # FIXME
def start_loading (self): def start_loading (self):
self.logger.debug ("dispatching load process") self.logger.debug ("dispatching load process")