Rev 16: Simplify output_lines. in http://people.ubuntu.com/~robertc/baz2.0/plugins/groupcompress/trunk
Robert Collins
robertc at robertcollins.net
Thu Jul 24 03:39:50 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/plugins/groupcompress/trunk
------------------------------------------------------------
revno: 16
revision-id: robertc at robertcollins.net-20080724023950-rl13uu60j66wks61
parent: robertc at robertcollins.net-20080724015151-vul2s7bru8fqytjl
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Thu 2008-07-24 12:39:50 +1000
message:
Simplify output_lines.
modified:
groupcompress.py groupcompress.py-20080705181503-ccbxd6xuy1bdnrpu-8
=== modified file 'groupcompress.py'
--- a/groupcompress.py 2008-07-24 01:51:51 +0000
+++ b/groupcompress.py 2008-07-24 02:39:50 +0000
@@ -137,7 +137,6 @@
line_locations = self.line_locations
range_len = 0
range_start = 0
- flush_range = self.flush_range
copy_ends = None
# We either copy a range (while there are reusable lines) or we
# insert new lines. To find reusable lines we traverse
@@ -152,7 +151,7 @@
else:
range_len += 1
else:
- locations, next = line_locations[line]
+ locations = line_locations[line]
if copy_ends:
next_locations = locations.intersection(copy_ends)
if len(next_locations):
@@ -164,7 +163,7 @@
if copy_ends:
result.append((min(copy_ends) - range_len, range_start, range_len))
range_len = 1
- copy_ends = next
+ copy_ends = set(loc + 1 for loc in locations)
range_start = pos
pos += 1
if copy_ends:
@@ -197,7 +196,6 @@
new_lines.append('sha1: %s\n' % sha1)
index_lines = [False, False]
pos = 0
- line_locations = self.line_locations
range_len = 0
range_start = 0
flush_range = self.flush_range
@@ -209,13 +207,13 @@
for old_start, new_start, range_len in blocks:
if new_start != current_pos:
# non-matching region
- flush_range(False, current_pos, None, new_start - current_pos,
+ flush_range(current_pos, None, new_start - current_pos,
lines, new_lines, index_lines)
current_pos = new_start + range_len
if not range_len:
continue
- flush_range(True, new_start, [old_start + range_len], range_len,
- lines, new_lines, index_lines)
+ flush_range(new_start, old_start, range_len, lines,
+ new_lines, index_lines)
delta_start = (self.endpoint, len(self.lines))
self.output_lines(new_lines, index_lines)
trim_encoding_newline(lines)
@@ -240,13 +238,12 @@
sha1 = sha_strings(lines)
return lines, sha1
- def flush_range(self, copying, range_start, copy_ends, range_len, lines, new_lines, index_lines):
+ def flush_range(self, range_start, copy_start, range_len, lines, new_lines, index_lines):
if not range_len:
return
insert_instruction = "i,%d\n" % range_len
- if copying:
+ if copy_start is not None:
# range stops, flush and start a new copy range
- copy_start = min(copy_ends) - range_len
stop_byte = self.line_offsets[copy_start + range_len - 1]
if copy_start == 0:
start_byte = 0
@@ -263,7 +260,7 @@
new_lines.append(insert_instruction)
new_lines.extend(lines[range_start:range_start+range_len])
index_lines.append(False)
- index_lines.extend([not copying]*range_len)
+ index_lines.extend([copy_start is None]*range_len)
def output_lines(self, new_lines, index_lines):
"""Output some lines.
@@ -274,15 +271,15 @@
"""
endpoint = self.endpoint
offset = len(self.lines)
+ line_append = self.line_offsets.append
+ setdefault = self.line_locations.setdefault
for (pos, line), index in izip(enumerate(new_lines), index_lines):
- self.lines.append(line)
endpoint += len(line)
- self.line_offsets.append(endpoint)
+ line_append(endpoint)
if index:
- indices, next_lines = self.line_locations.setdefault(line,
- (set(), set()))
+ indices = setdefault(line, set())
indices.add(pos + offset)
- next_lines.add(pos + offset + 1)
+ self.lines.extend(new_lines)
self.endpoint = endpoint
def ratio(self):
More information about the bazaar-commits
mailing list