aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2009-11-03 00:06:08 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2009-11-03 00:06:08 (GMT)
commit0109ea57045b7d85367cd201d288a7683e20319c (patch)
tree4a0fdc729320ad126647fe5835627c2f6f49e476
parent68af6dc389055d590ba7746aea283b4e36ee68d0 (diff)
downloadfusearchive-0109ea57045b7d85367cd201d288a7683e20319c.zip
fusearchive-0109ea57045b7d85367cd201d288a7683e20319c.tar.gz
fusearchive-0109ea57045b7d85367cd201d288a7683e20319c.tar.bz2
Keep track of length as long as possible so we don't have to loop over
chunk lengths or rejoin our string all the time
-rw-r--r--FuseArchive/ChunkBuffer.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/FuseArchive/ChunkBuffer.py b/FuseArchive/ChunkBuffer.py
index 89d468e..575f5aa 100644
--- a/FuseArchive/ChunkBuffer.py
+++ b/FuseArchive/ChunkBuffer.py
@@ -5,11 +5,14 @@ import logging
class ChunkBuffer:
def __init__( self, data = '' ):
logging.debug( "Creating chunkbuffer: %s" % data )
+ self.l = len( data )
self.chunk = [ data ]
def append( self, s ):
+ self.l += len( s )
self.chunk.append( s )
+ # Note: replace doesn't effect length so we don't update it
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
@@ -18,17 +21,11 @@ class ChunkBuffer:
self.chunk = [ s[ :start ], buf[ :l ], s[ end: ] ]
def length( self ):
- if len( self.chunk ) > 5:
- self._simplify()
-
- l = 0;
- for c in self.chunk:
- l += len( c )
-
- return l
+ return self.l
def truncate( self, l ):
s = ''.join( self.chunk )
+ self.l = l
self.chunk = [ s[ :l ] ]
def _simplify( self ):