Path 1: 11 calls (0.39)

3 (11)

list (11) None (11)

1def get_grouped_opcodes(self, n=3):
2        """ Isolate change clusters by eliminating ranges with no changes.
3
4        Return a generator of groups with up to n lines of context.
5        Each group is in the same format as returned by get_opcodes().
6
7        >>> from pprint import pprint
8        >>> a = list(map(str, range(1,40)))
9        >>> b = a[:]
10        >>> b[8:8] = ['i']     # Make an insertion
11        >>> b[20] += 'x'       # Make a replacement
12        >>> b[23:28] = []      # Make a deletion
13        >>> b[30] += 'y'       # Make another replacement
14        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
15        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
16         [('equal', 16, 19, 17, 20),
17          ('replace', 19, 20, 20, 21),
18          ('equal', 20, 22, 21, 23),
19          ('delete', 22, 27, 23, 23),
20          ('equal', 27, 30, 23, 26)],
21         [('equal', 31, 34, 27, 30),
22          ('replace', 34, 35, 30, 31),
23          ('equal', 35, 38, 31, 34)]]
24        """
25
26        codes = self.get_opcodes()
27        if not codes:
28            codes = [("equal", 0, 1, 0, 1)]
29        # Fixup leading and trailing groups if they show no changes.
30        if codes[0][0] == 'equal':
31            tag, i1, i2, j1, j2 = codes[0]
32            codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2
33        if codes[-1][0] == 'equal':
34            tag, i1, i2, j1, j2 = codes[-1]
35            codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
36
37        nn = n + n
38        group = []
39        for tag, i1, i2, j1, j2 in codes:
40            # End the current group and start a new one whenever
41            # there is a large range with no changes.
42            if tag == 'equal' and i2-i1 > nn:
43                group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))
44                yield group
45                group = []
46                i1, j1 = max(i1, i2-n), max(j1, j2-n)
47            group.append((tag, i1, i2, j1 ,j2))
48        if group and not (len(group)==1 and group[0][0] == 'equal'):
49            yield group
            

Path 2: 6 calls (0.21)

3 (6)

1def get_grouped_opcodes(self, n=3):
2        """ Isolate change clusters by eliminating ranges with no changes.
3
4        Return a generator of groups with up to n lines of context.
5        Each group is in the same format as returned by get_opcodes().
6
7        >>> from pprint import pprint
8        >>> a = list(map(str, range(1,40)))
9        >>> b = a[:]
10        >>> b[8:8] = ['i']     # Make an insertion
11        >>> b[20] += 'x'       # Make a replacement
12        >>> b[23:28] = []      # Make a deletion
13        >>> b[30] += 'y'       # Make another replacement
14        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
15        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
16         [('equal', 16, 19, 17, 20),
17          ('replace', 19, 20, 20, 21),
18          ('equal', 20, 22, 21, 23),
19          ('delete', 22, 27, 23, 23),
20          ('equal', 27, 30, 23, 26)],
21         [('equal', 31, 34, 27, 30),
22          ('replace', 34, 35, 30, 31),
23          ('equal', 35, 38, 31, 34)]]
24        """
25
26        codes = self.get_opcodes()
27        if not codes:
28            codes = [("equal", 0, 1, 0, 1)]
29        # Fixup leading and trailing groups if they show no changes.
30        if codes[0][0] == 'equal':
31            tag, i1, i2, j1, j2 = codes[0]
32            codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2
33        if codes[-1][0] == 'equal':
34            tag, i1, i2, j1, j2 = codes[-1]
35            codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
36
37        nn = n + n
38        group = []
39        for tag, i1, i2, j1, j2 in codes:
40            # End the current group and start a new one whenever
41            # there is a large range with no changes.
42            if tag == 'equal' and i2-i1 > nn:
43                group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))
44                yield group
45                group = []
46                i1, j1 = max(i1, i2-n), max(j1, j2-n)
47            group.append((tag, i1, i2, j1 ,j2))
48        if group and not (len(group)==1 and group[0][0] == 'equal'):
49            yield group
            

Path 3: 6 calls (0.21)

3 (6)

list (6) None (6)

1def get_grouped_opcodes(self, n=3):
2        """ Isolate change clusters by eliminating ranges with no changes.
3
4        Return a generator of groups with up to n lines of context.
5        Each group is in the same format as returned by get_opcodes().
6
7        >>> from pprint import pprint
8        >>> a = list(map(str, range(1,40)))
9        >>> b = a[:]
10        >>> b[8:8] = ['i']     # Make an insertion
11        >>> b[20] += 'x'       # Make a replacement
12        >>> b[23:28] = []      # Make a deletion
13        >>> b[30] += 'y'       # Make another replacement
14        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
15        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
16         [('equal', 16, 19, 17, 20),
17          ('replace', 19, 20, 20, 21),
18          ('equal', 20, 22, 21, 23),
19          ('delete', 22, 27, 23, 23),
20          ('equal', 27, 30, 23, 26)],
21         [('equal', 31, 34, 27, 30),
22          ('replace', 34, 35, 30, 31),
23          ('equal', 35, 38, 31, 34)]]
24        """
25
26        codes = self.get_opcodes()
27        if not codes:
28            codes = [("equal", 0, 1, 0, 1)]
29        # Fixup leading and trailing groups if they show no changes.
30        if codes[0][0] == 'equal':
31            tag, i1, i2, j1, j2 = codes[0]
32            codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2
33        if codes[-1][0] == 'equal':
34            tag, i1, i2, j1, j2 = codes[-1]
35            codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
36
37        nn = n + n
38        group = []
39        for tag, i1, i2, j1, j2 in codes:
40            # End the current group and start a new one whenever
41            # there is a large range with no changes.
42            if tag == 'equal' and i2-i1 > nn:
43                group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))
44                yield group
45                group = []
46                i1, j1 = max(i1, i2-n), max(j1, j2-n)
47            group.append((tag, i1, i2, j1 ,j2))
48        if group and not (len(group)==1 and group[0][0] == 'equal'):
49            yield group
            

Path 4: 2 calls (0.07)

3 (2)

1def get_grouped_opcodes(self, n=3):
2        """ Isolate change clusters by eliminating ranges with no changes.
3
4        Return a generator of groups with up to n lines of context.
5        Each group is in the same format as returned by get_opcodes().
6
7        >>> from pprint import pprint
8        >>> a = list(map(str, range(1,40)))
9        >>> b = a[:]
10        >>> b[8:8] = ['i']     # Make an insertion
11        >>> b[20] += 'x'       # Make a replacement
12        >>> b[23:28] = []      # Make a deletion
13        >>> b[30] += 'y'       # Make another replacement
14        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
15        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
16         [('equal', 16, 19, 17, 20),
17          ('replace', 19, 20, 20, 21),
18          ('equal', 20, 22, 21, 23),
19          ('delete', 22, 27, 23, 23),
20          ('equal', 27, 30, 23, 26)],
21         [('equal', 31, 34, 27, 30),
22          ('replace', 34, 35, 30, 31),
23          ('equal', 35, 38, 31, 34)]]
24        """
25
26        codes = self.get_opcodes()
27        if not codes:
28            codes = [("equal", 0, 1, 0, 1)]
29        # Fixup leading and trailing groups if they show no changes.
30        if codes[0][0] == 'equal':
31            tag, i1, i2, j1, j2 = codes[0]
32            codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2
33        if codes[-1][0] == 'equal':
34            tag, i1, i2, j1, j2 = codes[-1]
35            codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
36
37        nn = n + n
38        group = []
39        for tag, i1, i2, j1, j2 in codes:
40            # End the current group and start a new one whenever
41            # there is a large range with no changes.
42            if tag == 'equal' and i2-i1 > nn:
43                group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))
44                yield group
45                group = []
46                i1, j1 = max(i1, i2-n), max(j1, j2-n)
47            group.append((tag, i1, i2, j1 ,j2))
48        if group and not (len(group)==1 and group[0][0] == 'equal'):
49            yield group
            

Path 5: 2 calls (0.07)

3 (2)

list (2) None (2)

1def get_grouped_opcodes(self, n=3):
2        """ Isolate change clusters by eliminating ranges with no changes.
3
4        Return a generator of groups with up to n lines of context.
5        Each group is in the same format as returned by get_opcodes().
6
7        >>> from pprint import pprint
8        >>> a = list(map(str, range(1,40)))
9        >>> b = a[:]
10        >>> b[8:8] = ['i']     # Make an insertion
11        >>> b[20] += 'x'       # Make a replacement
12        >>> b[23:28] = []      # Make a deletion
13        >>> b[30] += 'y'       # Make another replacement
14        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
15        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
16         [('equal', 16, 19, 17, 20),
17          ('replace', 19, 20, 20, 21),
18          ('equal', 20, 22, 21, 23),
19          ('delete', 22, 27, 23, 23),
20          ('equal', 27, 30, 23, 26)],
21         [('equal', 31, 34, 27, 30),
22          ('replace', 34, 35, 30, 31),
23          ('equal', 35, 38, 31, 34)]]
24        """
25
26        codes = self.get_opcodes()
27        if not codes:
28            codes = [("equal", 0, 1, 0, 1)]
29        # Fixup leading and trailing groups if they show no changes.
30        if codes[0][0] == 'equal':
31            tag, i1, i2, j1, j2 = codes[0]
32            codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2
33        if codes[-1][0] == 'equal':
34            tag, i1, i2, j1, j2 = codes[-1]
35            codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
36
37        nn = n + n
38        group = []
39        for tag, i1, i2, j1, j2 in codes:
40            # End the current group and start a new one whenever
41            # there is a large range with no changes.
42            if tag == 'equal' and i2-i1 > nn:
43                group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))
44                yield group
45                group = []
46                i1, j1 = max(i1, i2-n), max(j1, j2-n)
47            group.append((tag, i1, i2, j1 ,j2))
48        if group and not (len(group)==1 and group[0][0] == 'equal'):
49            yield group
            

Path 6: 1 calls (0.04)

3 (1)

list (3) None (1)

1def get_grouped_opcodes(self, n=3):
2        """ Isolate change clusters by eliminating ranges with no changes.
3
4        Return a generator of groups with up to n lines of context.
5        Each group is in the same format as returned by get_opcodes().
6
7        >>> from pprint import pprint
8        >>> a = list(map(str, range(1,40)))
9        >>> b = a[:]
10        >>> b[8:8] = ['i']     # Make an insertion
11        >>> b[20] += 'x'       # Make a replacement
12        >>> b[23:28] = []      # Make a deletion
13        >>> b[30] += 'y'       # Make another replacement
14        >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
15        [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
16         [('equal', 16, 19, 17, 20),
17          ('replace', 19, 20, 20, 21),
18          ('equal', 20, 22, 21, 23),
19          ('delete', 22, 27, 23, 23),
20          ('equal', 27, 30, 23, 26)],
21         [('equal', 31, 34, 27, 30),
22          ('replace', 34, 35, 30, 31),
23          ('equal', 35, 38, 31, 34)]]
24        """
25
26        codes = self.get_opcodes()
27        if not codes:
28            codes = [("equal", 0, 1, 0, 1)]
29        # Fixup leading and trailing groups if they show no changes.
30        if codes[0][0] == 'equal':
31            tag, i1, i2, j1, j2 = codes[0]
32            codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2
33        if codes[-1][0] == 'equal':
34            tag, i1, i2, j1, j2 = codes[-1]
35            codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
36
37        nn = n + n
38        group = []
39        for tag, i1, i2, j1, j2 in codes:
40            # End the current group and start a new one whenever
41            # there is a large range with no changes.
42            if tag == 'equal' and i2-i1 > nn:
43                group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))
44                yield group
45                group = []
46                i1, j1 = max(i1, i2-n), max(j1, j2-n)
47            group.append((tag, i1, i2, j1 ,j2))
48        if group and not (len(group)==1 and group[0][0] == 'equal'):
49            yield group