Skip to content

Commit 682f483

Browse files
committed
First profiling run revealed that the copy function was a serious slowdown. Now its twice as fast compared to the previous version, but still about 8 times slower than the brute force approach
1 parent 5d18685 commit 682f483

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

fun.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import mmap
1313
from itertools import islice, izip
1414

15-
from copy import copy
1615
from cStringIO import StringIO
1716

1817
# INVARIANTS
@@ -82,6 +81,9 @@ def _move_delta_lbound(d, bytes):
8281
# END handle data
8382

8483
return d
84+
85+
def delta_duplicate(src):
86+
return DeltaChunk(src.to, src.ts, src.so, src.data)
8587

8688
class DeltaChunk(object):
8789
"""Represents a piece of a delta, it can either add new data, or copy existing
@@ -277,7 +279,7 @@ def apply(self, bbuf, write, lbound_offset=0, size=0):
277279
cdi = _closest_index(self, absofs)
278280
cd = self[cdi]
279281
if cd.to != absofs:
280-
tcd = copy(cd)
282+
tcd = delta_duplicate(cd)
281283
_move_delta_lbound(tcd, absofs - cd.to)
282284
_set_delta_rbound(tcd, min(tcd.ts, size))
283285
dapply(tcd, bbuf, write)
@@ -293,7 +295,7 @@ def apply(self, bbuf, write, lbound_offset=0, size=0):
293295
dapply(cd, bbuf, write)
294296
size -= cd.ts
295297
else:
296-
tcd = copy(cd)
298+
tcd = delta_duplicate(cd)
297299
_set_delta_rbound(tcd, size)
298300
dapply(tcd, bbuf, write)
299301
size -= tcd.ts
@@ -355,7 +357,7 @@ def __getslice__(self, absofs, size):
355357
ndcl = self.__class__()
356358

357359
if cd.to != absofs:
358-
tcd = copy(cd)
360+
tcd = delta_duplicate(cd)
359361
_move_delta_lbound(tcd, absofs - cd.to)
360362
_set_delta_rbound(tcd, min(tcd.ts, size))
361363
ndcl.append(tcd)
@@ -367,10 +369,10 @@ def __getslice__(self, absofs, size):
367369
# are we larger than the current block
368370
cd = self[cdi]
369371
if cd.ts <= size:
370-
ndcl.append(copy(cd))
372+
ndcl.append(delta_duplicate(cd))
371373
size -= cd.ts
372374
else:
373-
tcd = copy(cd)
375+
tcd = delta_duplicate(cd)
374376
_set_delta_rbound(tcd, size)
375377
ndcl.append(tcd)
376378
size -= tcd.ts

stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def _set_cache_(self, attr):
358358

359359
self._mm_target.seek(0)
360360

361-
def _set_cache_(self, attr):
361+
def _set_cache_brute_(self, attr):
362362
"""If we are here, we apply the actual deltas"""
363363

364364
buffer_info_list = list()

0 commit comments

Comments
 (0)