--- py3k/Lib/difflib.py 2010-12-29 21:24:08.050655792 +0100 +++ cy3k/Lib/difflib.py 2011-03-21 19:40:00.876894538 +0100 @@ -407,7 +407,7 @@ # Windiff ends up at the same place as diff, but by pairing up # the unique 'b's and then matching the first two 'a's. - a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.bjunk.__contains__ + a, b, b2j, bjunk = self.a, self.b, self.b2j, self.bjunk besti, bestj, bestsize = alo, blo, 0 # find longest junk-free match # during an iteration of the loop, j2len[j] = length of longest @@ -435,11 +435,11 @@ # the inner loop above, but also means "the best" match so far # doesn't contain any junk *or* popular non-junk elements. while besti > alo and bestj > blo and \ - not isbjunk(b[bestj-1]) and \ + b[bestj-1] not in bjunk and \ a[besti-1] == b[bestj-1]: besti, bestj, bestsize = besti-1, bestj-1, bestsize+1 while besti+bestsize < ahi and bestj+bestsize < bhi and \ - not isbjunk(b[bestj+bestsize]) and \ + b[bestj+bestsize] not in bjunk and \ a[besti+bestsize] == b[bestj+bestsize]: bestsize += 1 @@ -451,11 +451,11 @@ # interesting match, this is clearly the right thing to do, # because no other kind of match is possible in the regions. while besti > alo and bestj > blo and \ - isbjunk(b[bestj-1]) and \ + b[bestj-1] in bjunk and \ a[besti-1] == b[bestj-1]: besti, bestj, bestsize = besti-1, bestj-1, bestsize+1 while besti+bestsize < ahi and bestj+bestsize < bhi and \ - isbjunk(b[bestj+bestsize]) and \ + b[bestj+bestsize] in bjunk and \ a[besti+bestsize] == b[bestj+bestsize]: bestsize = bestsize + 1 @@ -680,9 +680,9 @@ # avail[x] is the number of times x appears in 'b' less the # number of times we've seen it in 'a' so far ... kinda avail = {} - availhas, matches = avail.__contains__, 0 + matches = 0 for elt in self.a: - if availhas(elt): + if elt in avail: numb = avail[elt] else: numb = fullbcount.get(elt, 0) @@ -1585,7 +1585,7 @@ yield from_line, to_line, found_diff -_file_template = """ +_file_template = _xx_file_template = """ @@ -1605,7 +1605,7 @@ """ -_styles = """ +_styles = _xx_styles = """ table.diff {font-family:Courier; border:medium;} .diff_header {background-color:#e0e0e0} td.diff_header {text-align:right} @@ -1614,7 +1614,7 @@ .diff_chg {background-color:#ffff77} .diff_sub {background-color:#ffaaaa}""" -_table_template = """ +_table_template = _xx_table_template = """ @@ -1624,7 +1624,7 @@ %(data_rows)s
""" -_legend = """ +_legend = _xx_legend = """
Legends
@@ -1657,10 +1657,10 @@ See tools/scripts/diff.py for an example usage of this class. """ - _file_template = _file_template - _styles = _styles - _table_template = _table_template - _legend = _legend + _file_template = _xx_file_template + _styles = _xx_styles + _table_template = _xx_table_template + _legend = _xx_legend _default_prefix = 0 def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None, --- /dev/null 2011-03-06 10:28:00.903286545 +0100 +++ cy3k/Lib/difflib.pxd 2011-03-21 13:27:41.928073664 +0100 @@ -0,0 +1,27 @@ + +cimport cython + +cdef _calculate_ratio(Py_ssize_t matches, Py_ssize_t length) + +cdef class SequenceMatcher: + cdef object a + cdef object b + cdef dict b2j + cdef dict fullbcount + cdef list matching_blocks + cdef list opcodes + cdef object isjunk + cdef object autojunk + cdef set bjunk + cdef set bpopular + + @cython.locals(b2j=dict, + besti=Py_ssize_t, bestj=Py_ssize_t, bestsize=Py_ssize_t, + i=Py_ssize_t, j=Py_ssize_t, k=Py_ssize_t) + cpdef find_longest_match(self, Py_ssize_t alo, Py_ssize_t ahi, Py_ssize_t blo, Py_ssize_t bhi) + + @cython.locals(matches=Py_ssize_t) + cpdef quick_ratio(self) + + @cython.locals(la=Py_ssize_t, lb=Py_ssize_t) + cpdef real_quick_ratio(self)