diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2011-06-09 23:22:46 +0200 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2011-06-09 23:22:46 +0200 |
| commit | 68fba826cdfd0de532ccf14c9ad94bf035a36e1b (patch) | |
| tree | 7a394b1886b52172be98a0f53bcff831d8b13f85 | |
| parent | b00bc5e4c0e8eb47d0bf59c0a2c1f5399f4c8f58 (diff) | |
| download | smmap-68fba826cdfd0de532ccf14c9ad94bf035a36e1b.tar.gz | |
Optimized __getslice__ implementation a bit
| -rw-r--r-- | smmap/buf.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/smmap/buf.py b/smmap/buf.py index 68e7c33..d1be1b6 100644 --- a/smmap/buf.py +++ b/smmap/buf.py @@ -61,22 +61,17 @@ class MappedMemoryBuffer(object): else: l = j-i # total length ofs = i - # keep tokens, and join afterwards. This is faster - # as it can preallocate the total amoint of space needed - # (and its verified the implementation does that) - # Question is whether the list allocation doesn't counteract this, - # but lets see ... - tokens = list() - tappend = tokens.append - + # Keeping tokens in a list could possible be faster, but the list + # overhead outweighs the benefits (tested) ! + md = str() while l: c.use_region(ofs, l) d = c.buffer()[:l] ofs += len(d) l -= len(d) - tappend(d) + md += d #END while there are bytes to read - return ''.join(tokens) + return md # END fast or slow path #{ Interface |
