|
22 | 22 | zlib
|
23 | 23 | )
|
24 | 24 |
|
| 25 | +has_perf_mod = False |
25 | 26 | try:
|
26 | 27 | from _perf import apply_delta as c_apply_delta
|
| 28 | + has_perf_mod = True |
27 | 29 | except ImportError:
|
28 | 30 | pass
|
29 | 31 |
|
@@ -330,7 +332,7 @@ def __init__(self, stream_list):
|
330 | 332 | self._dstreams = tuple(stream_list[:-1])
|
331 | 333 | self._br = 0
|
332 | 334 |
|
333 |
| - def _set_cache_too_slow(self, attr): |
| 335 | + def _set_cache_too_slow_without_c(self, attr): |
334 | 336 | # the direct algorithm is fastest and most direct if there is only one
|
335 | 337 | # delta. Also, the extra overhead might not be worth it for items smaller
|
336 | 338 | # than X - definitely the case in python, every function call costs
|
@@ -366,6 +368,15 @@ def _set_cache_too_slow(self, attr):
|
366 | 368 | self._mm_target.seek(0)
|
367 | 369 |
|
368 | 370 | def _set_cache_(self, attr):
|
| 371 | + """Determine which version to use depending on the configuration of the deltas |
| 372 | + :note: we are only called if we have the performance module""" |
| 373 | + # otherwise it depends on the amount of memory to shift around |
| 374 | + if len(self._dstreams) > 1 and self._bstream.size < 150000: |
| 375 | + return self._set_cache_too_slow_without_c(attr) |
| 376 | + else: |
| 377 | + return self._set_cache_brute_(attr) |
| 378 | + |
| 379 | + def _set_cache_brute_(self, attr): |
369 | 380 | """If we are here, we apply the actual deltas"""
|
370 | 381 |
|
371 | 382 | buffer_info_list = list()
|
@@ -438,6 +449,13 @@ def _set_cache_(self, attr):
|
438 | 449 | self._mm_target = bbuf
|
439 | 450 | self._size = final_target_size
|
440 | 451 |
|
| 452 | + |
| 453 | + #{ Configuration |
| 454 | + if not has_perf_mod: |
| 455 | + _set_cache_ = _set_cache_brute_ |
| 456 | + |
| 457 | + #} END configuration |
| 458 | + |
441 | 459 | def read(self, count=0):
|
442 | 460 | bl = self._size - self._br # bytes left
|
443 | 461 | if count < 1 or count > bl:
|
@@ -654,4 +672,7 @@ def close(self):
|
654 | 672 | def write(self, data):
|
655 | 673 | return len(data)
|
656 | 674 |
|
| 675 | + |
657 | 676 | #} END W streams
|
| 677 | + |
| 678 | + |
0 commit comments