Skip to content

Commit e0b0bec

Browse files
committed
Restore compatibility to python 3.0 to 3.4
1 parent c1998a0 commit e0b0bec

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

doc/source/changes.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
#########
44

5+
**********
6+
v0.8.5
7+
**********
8+
- 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
9+
510
**********
611
v0.8.4
712
**********

smmap/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__author__ = "Sebastian Thiel"
44
__contact__ = "[email protected]"
55
__homepage__ = "https://github.com/Byron/smmap"
6-
version_info = (0, 8, 4)
6+
version_info = (0, 8, 5)
77
__version__ = '.'.join(str(i) for i in version_info)
88

99
# make everything available in root package for convenience

smmap/buf.py

+27-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
__all__ = ["SlidingWindowMapBuffer"]
55

6+
import sys
7+
68
try:
79
bytes
810
except NameError:
@@ -79,16 +81,31 @@ def __getslice__(self, i, j):
7981
ofs = i
8082
# It's fastest to keep tokens and join later, especially in py3, which was 7 times slower
8183
# in the previous iteration of this code
82-
md = list()
83-
while l:
84-
c.use_region(ofs, l)
85-
assert c.is_valid()
86-
d = c.buffer()[:l]
87-
ofs += len(d)
88-
l -= len(d)
89-
md.append(d)
90-
# END while there are bytes to read
91-
return bytes().join(md)
84+
pyvers = sys.version_info[:2]
85+
if (3, 0) <= pyvers <= (3, 3):
86+
# Memory view cannot be joined below python 3.4 ...
87+
out = bytes()
88+
while l:
89+
c.use_region(ofs, l)
90+
assert c.is_valid()
91+
d = c.buffer()[:l]
92+
ofs += len(d)
93+
l -= len(d)
94+
# This is slower than the join ... but what can we do ...
95+
out += d
96+
# END while there are bytes to read
97+
return out
98+
else:
99+
md = list()
100+
while l:
101+
c.use_region(ofs, l)
102+
assert c.is_valid()
103+
d = c.buffer()[:l]
104+
ofs += len(d)
105+
l -= len(d)
106+
md.append(d)
107+
# END while there are bytes to read
108+
return bytes().join(md)
92109
# END fast or slow path
93110
#{ Interface
94111

0 commit comments

Comments
 (0)