diff options
author | Steve Slaven <bpk@hoopajoo.net> | 2009-11-02 23:36:12 (GMT) |
---|---|---|
committer | Steve Slaven <bpk@hoopajoo.net> | 2009-11-02 23:36:12 (GMT) |
commit | b4f754a596f8d262d0f3089c37bf47c73d8ccfc1 (patch) | |
tree | 11d2287b9bb38961b216c4b03de9c722eaee0a6f /FuseArchive/ChunkBuffer.py | |
parent | c44db1796c8389d89acd4122da6ffdd72998d6a0 (diff) | |
download | fusearchive-b4f754a596f8d262d0f3089c37bf47c73d8ccfc1.zip fusearchive-b4f754a596f8d262d0f3089c37bf47c73d8ccfc1.tar.gz fusearchive-b4f754a596f8d262d0f3089c37bf47c73d8ccfc1.tar.bz2 |
Use a stringbuffer list instead of appending strings, apparently python
string handling when appending/using large strings is very bad
Diffstat (limited to 'FuseArchive/ChunkBuffer.py')
-rw-r--r-- | FuseArchive/ChunkBuffer.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/FuseArchive/ChunkBuffer.py b/FuseArchive/ChunkBuffer.py new file mode 100644 index 0000000..4ef6370 --- /dev/null +++ b/FuseArchive/ChunkBuffer.py @@ -0,0 +1,21 @@ +import logging + +# Handle efficient operations on a non-fixed length buffer like appending, +# replacing, reading chunks, etc +class ChunkBuffer: + def __init__( self, data = '' ): + logging.debug( "Creating chunkbuffer: %s" % data ) + self.chunk = list( data ) + + def append( self, s ): + self.chunk.extend( list( s ) ) + + def replace( self, s, start, end ): + self.chunk + + def length( self ): + return len( self.chunk ) + + def string(self): + logging.debug( "Stringifying: %s" % self.chunk ) + return ''.join( self.chunk ) |