diff options
author | Steve Slaven <bpk@hoopajoo.net> | 2009-11-02 23:57:29 (GMT) |
---|---|---|
committer | Steve Slaven <bpk@hoopajoo.net> | 2009-11-02 23:57:29 (GMT) |
commit | 5ffcb57273d6476868397d215567eca6e48f9963 (patch) | |
tree | e654fc12c029494f7b4cdd8c3ab826172658514e /FuseArchive | |
parent | b4f754a596f8d262d0f3089c37bf47c73d8ccfc1 (diff) | |
download | fusearchive-5ffcb57273d6476868397d215567eca6e48f9963.zip fusearchive-5ffcb57273d6476868397d215567eca6e48f9963.tar.gz fusearchive-5ffcb57273d6476868397d215567eca6e48f9963.tar.bz2 |
Handle some of the string stuff more efficiently by not splitting
everything in to characters but trying to keep a string list around instead
Diffstat (limited to 'FuseArchive')
-rw-r--r-- | FuseArchive/ChunkBuffer.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/FuseArchive/ChunkBuffer.py b/FuseArchive/ChunkBuffer.py index 4ef6370..7b6beee 100644 --- a/FuseArchive/ChunkBuffer.py +++ b/FuseArchive/ChunkBuffer.py @@ -5,16 +5,31 @@ import logging class ChunkBuffer: def __init__( self, data = '' ): logging.debug( "Creating chunkbuffer: %s" % data ) - self.chunk = list( data ) + self.chunk = [ data ] def append( self, s ): - self.chunk.extend( list( s ) ) + self.chunk.append( s ) - def replace( self, s, start, end ): - self.chunk + def replace( self, buf, start, end ): + # We make a string of our chunk, then create a new list of the 3 + # strings, the start, new chunk, and remaining chunk + s = ''.join( self.chunk ) + l = end - start + self.chunk = [ s[ :start ], buf[ :l ], s[ end: ] ] def length( self ): - return len( self.chunk ) + if len( self.chunk ) > 5: + self._simplify() + + l = 0; + for c in self.chunk: + l += len( c ) + + return l + + def _simplify( self ): + logging.debug( "Simplify!" ) + self.chunk = [ ''.join( self.chunk ) ] def string(self): logging.debug( "Stringifying: %s" % self.chunk ) |