diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-06 15:55:09 +0100 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-06 15:55:09 +0100 |
| commit | e0b0becd97afb9b7ac434c5fabdadd20070d643d (patch) | |
| tree | d6a529fade1e1b9d3bea517f01eba622771a62fb | |
| parent | c1998a074d2fd1773322e4595f30a5ecbbd54e32 (diff) | |
| download | smmap-e0b0becd97afb9b7ac434c5fabdadd20070d643d.tar.gz | |
Restore compatibility to python 3.0 to 3.4v0.8.5
| -rw-r--r-- | doc/source/changes.rst | 5 | ||||
| -rw-r--r-- | smmap/__init__.py | 2 | ||||
| -rw-r--r-- | smmap/buf.py | 37 |
3 files changed, 33 insertions, 11 deletions
diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 6cf9c83..ec42369 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -3,6 +3,11 @@ Changelog ######### ********** +v0.8.5 +********** +- Fixed Python 3.0-3.3 regression, which also causes smmap to become about 3 times slower depending on the code path. It's related to this bug (http://bugs.python.org/issue15958), which was fixed in python 3.4 + +********** v0.8.4 ********** - Fixed Python 3 performance regression diff --git a/smmap/__init__.py b/smmap/__init__.py index 5f0e095..46b0002 100644 --- a/smmap/__init__.py +++ b/smmap/__init__.py @@ -3,7 +3,7 @@ __author__ = "Sebastian Thiel" __contact__ = "byronimo@gmail.com" __homepage__ = "https://github.com/Byron/smmap" -version_info = (0, 8, 4) +version_info = (0, 8, 5) __version__ = '.'.join(str(i) for i in version_info) # make everything available in root package for convenience diff --git a/smmap/buf.py b/smmap/buf.py index 17d2d36..b3b71c4 100644 --- a/smmap/buf.py +++ b/smmap/buf.py @@ -3,6 +3,8 @@ import sys __all__ = ["SlidingWindowMapBuffer"] +import sys + try: bytes except NameError: @@ -79,16 +81,31 @@ class SlidingWindowMapBuffer(object): ofs = i # It's fastest to keep tokens and join later, especially in py3, which was 7 times slower # in the previous iteration of this code - md = list() - while l: - c.use_region(ofs, l) - assert c.is_valid() - d = c.buffer()[:l] - ofs += len(d) - l -= len(d) - md.append(d) - # END while there are bytes to read - return bytes().join(md) + pyvers = sys.version_info[:2] + if (3, 0) <= pyvers <= (3, 3): + # Memory view cannot be joined below python 3.4 ... + out = bytes() + while l: + c.use_region(ofs, l) + assert c.is_valid() + d = c.buffer()[:l] + ofs += len(d) + l -= len(d) + # This is slower than the join ... but what can we do ... + out += d + # END while there are bytes to read + return out + else: + md = list() + while l: + c.use_region(ofs, l) + assert c.is_valid() + d = c.buffer()[:l] + ofs += len(d) + l -= len(d) + md.append(d) + # END while there are bytes to read + return bytes().join(md) # END fast or slow path #{ Interface |
