~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_py.py

  • Committer: John Arbash Meinel
  • Date: 2009-04-22 22:14:58 UTC
  • mto: This revision was merged to the branch mainline in revision 4301.
  • Revision ID: john@arbash-meinel.com-20090422221458-wg8pwibhdvgvvths
Change self._matching_lines to use a set rather than a list.
We need to consider memory consumption, etc, but it means we don't have
to cast into a set() to do the intersection check.
Might consider redoing the copy_ends code of _get_longest_match.

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
        for idx, do_index in enumerate(index):
119
119
            if not do_index:
120
120
                continue
121
 
            matches.setdefault(new_lines[idx], []).append(start_idx + idx)
 
121
            line = new_lines[idx]
 
122
            try:
 
123
                matches[line].add(start_idx + idx)
 
124
            except KeyError:
 
125
                matches[line] = set([start_idx + idx])
122
126
 
123
127
    def get_matches(self, line):
124
128
        """Return the lines which match the line in right."""
144
148
        range_len = 0
145
149
        copy_ends = None
146
150
        max_pos = len(lines)
 
151
        matching = self._matching_lines
147
152
        while pos < max_pos:
148
153
            if locations is None:
149
154
                # TODO: is try/except better than get(..., None)?
150
155
                try:
151
 
                    locations = self._matching_lines[lines[pos]]
 
156
                    locations = matching[lines[pos]]
152
157
                except KeyError:
153
158
                    locations = None
154
159
            if locations is None:
166
171
                else:
167
172
                    # We have a match started, compare to see if any of the
168
173
                    # current matches can be continued
169
 
                    next_locations = set(copy_ends).intersection(locations)
 
174
                    next_locations = locations.intersection(copy_ends)
170
175
                    if next_locations:
171
176
                        # At least one of the regions continues to match
172
177
                        copy_ends = [loc + 1 for loc in next_locations]