aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2009-11-03 00:45:00 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2009-11-03 00:45:00 (GMT)
commitcdde104c9c4a70ff801aec269494f1473944b81f (patch)
tree028f3a4fadb703a723aee5e74bad8c5c5dc0d084
parent8442f478923a1a6bd61c9eab779227ab7e7dff2c (diff)
downloadfusearchive-cdde104c9c4a70ff801aec269494f1473944b81f.zip
fusearchive-cdde104c9c4a70ff801aec269494f1473944b81f.tar.gz
fusearchive-cdde104c9c4a70ff801aec269494f1473944b81f.tar.bz2
Move chunkbuffer out a class level so we can try a couple different things
to see if we can optimize string() which is the slowest part now
-rw-r--r--FuseArchive/ChunkBuffer.py38
-rw-r--r--FuseArchive/ChunkBufferMem.py37
2 files changed, 41 insertions, 34 deletions
diff --git a/FuseArchive/ChunkBuffer.py b/FuseArchive/ChunkBuffer.py
index 575f5aa..134ce30 100644
--- a/FuseArchive/ChunkBuffer.py
+++ b/FuseArchive/ChunkBuffer.py
@@ -1,37 +1,7 @@
-import logging
+from ChunkBufferMem import ChunkBufferMem
+from ChunkBufferFile import ChunkBufferFile
# 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.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
- s = ''.join( self.chunk )
- l = end - start
- self.chunk = [ s[ :start ], buf[ :l ], s[ end: ] ]
-
- def length( self ):
- return self.l
-
- def truncate( self, l ):
- s = ''.join( self.chunk )
- self.l = l
- self.chunk = [ s[ :l ] ]
-
- def _simplify( self ):
- logging.debug( "Simplify!" )
- self.chunk = [ ''.join( self.chunk ) ]
-
- def string(self):
- logging.debug( "Stringifying: %s" % self.chunk )
- return ''.join( self.chunk )
+class ChunkBuffer(ChunkBufferMem):
+ pass
diff --git a/FuseArchive/ChunkBufferMem.py b/FuseArchive/ChunkBufferMem.py
new file mode 100644
index 0000000..e1599be
--- /dev/null
+++ b/FuseArchive/ChunkBufferMem.py
@@ -0,0 +1,37 @@
+import logging
+
+# Handle efficient operations on a non-fixed length buffer like appending,
+# replacing, reading chunks, etc
+class ChunkBufferMem:
+ 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
+ s = ''.join( self.chunk )
+ l = end - start
+ self.chunk = [ s[ :start ], buf[ :l ], s[ end: ] ]
+
+ def length( self ):
+ return self.l
+
+ def truncate( self, l ):
+ s = ''.join( self.chunk )
+ self.l = l
+ self.chunk = [ s[ :l ] ]
+
+ def _simplify( self ):
+ logging.debug( "Simplify!" )
+ self.chunk = [ ''.join( self.chunk ) ]
+
+ def string(self):
+ logging.debug( "Stringifying: %s" % self.chunk )
+ return ''.join( self.chunk )