Commit be0a763
* Use buffer `StringIO` with `GzipFile` on Python 2
In `GZip`'s `decode` method, we knew that `BytesIO` was always copying
the data. So we merely ensured the data was in a form that made it easy
to copy (i.e. a contiguous buffer). However we have since learned we can
do better as the Python 2 implementation of `StringIO` merely takes the
buffer without copying it. So use `StringIO` on Python 2 to avoid a copy
here. As this support doesn't extend to Python 3, continue using
`BytesIO` in that case. Should avoid copies on Python 2 in the general
case when using `GZip`'s `decode`; thus, improving performance there.
ref: http://www.hydrogen18.com/blog/unpickling-buffers.html
ref: https://github.com/python/cpython/blob/2.7/Modules/cStringIO.c#L716
ref: https://github.com/python/cpython/blob/2.7/Modules/cStringIO.c#L681
ref: https://github.com/python/cpython/blob/2.7/Modules/cStringIO.c#L160
* Note GZip.decode avoids copying data on Python 2
1 parent 57b9478 commit be0a763
2 files changed
+10
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
| |||
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 58 | + | |
| 59 | + | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | | - | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | | - | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
0 commit comments