Show More
@@ -22,6 +22,16 b' StringIO = cStringIO.StringIO' | |||||
22 | # mmap and simply use memmove. This avoids creating a bunch of large |
|
22 | # mmap and simply use memmove. This avoids creating a bunch of large | |
23 | # temporary string buffers. |
|
23 | # temporary string buffers. | |
24 |
|
24 | |||
|
25 | def _pull(dst, src, l): # pull l bytes from src | |||
|
26 | while l: | |||
|
27 | f = src.pop() | |||
|
28 | if f[0] > l: # do we need to split? | |||
|
29 | src.append((f[0] - l, f[1] + l)) | |||
|
30 | dst.append((l, f[1])) | |||
|
31 | return | |||
|
32 | dst.append(f) | |||
|
33 | l -= f[0] | |||
|
34 | ||||
25 | def patches(a, bins): |
|
35 | def patches(a, bins): | |
26 | if not bins: |
|
36 | if not bins: | |
27 | return a |
|
37 | return a | |
@@ -55,16 +65,6 b' def patches(a, bins):' | |||||
55 | m.seek(pos) |
|
65 | m.seek(pos) | |
56 | for p in bins: m.write(p) |
|
66 | for p in bins: m.write(p) | |
57 |
|
67 | |||
58 | def pull(dst, src, l): # pull l bytes from src |
|
|||
59 | while l: |
|
|||
60 | f = src.pop() |
|
|||
61 | if f[0] > l: # do we need to split? |
|
|||
62 | src.append((f[0] - l, f[1] + l)) |
|
|||
63 | dst.append((l, f[1])) |
|
|||
64 | return |
|
|||
65 | dst.append(f) |
|
|||
66 | l -= f[0] |
|
|||
67 |
|
||||
68 | def collect(buf, list): |
|
68 | def collect(buf, list): | |
69 | start = buf |
|
69 | start = buf | |
70 | for l, p in reversed(list): |
|
70 | for l, p in reversed(list): | |
@@ -84,8 +84,8 b' def patches(a, bins):' | |||||
84 | while pos < end: |
|
84 | while pos < end: | |
85 | m.seek(pos) |
|
85 | m.seek(pos) | |
86 | p1, p2, l = struct.unpack(">lll", m.read(12)) |
|
86 | p1, p2, l = struct.unpack(">lll", m.read(12)) | |
87 | pull(new, frags, p1 - last) # what didn't change |
|
87 | _pull(new, frags, p1 - last) # what didn't change | |
88 | pull([], frags, p2 - p1) # what got deleted |
|
88 | _pull([], frags, p2 - p1) # what got deleted | |
89 | new.append((l, pos + 12)) # what got added |
|
89 | new.append((l, pos + 12)) # what got added | |
90 | pos += l + 12 |
|
90 | pos += l + 12 | |
91 | last = p2 |
|
91 | last = p2 |
General Comments 0
You need to be logged in to leave comments.
Login now