/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/_annotator_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2009-06-24 19:21:04 UTC
  • mto: This revision was merged to the branch mainline in revision 4522.
  • Revision ID: john@arbash-meinel.com-20090624192104-3nwr1a5ipgtv2xc7
Tune the inner resolution loop a bit. Down to 125ms from 200+ms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    void Py_INCREF_ptr "Py_INCREF" (PyObject *)
47
47
 
48
48
    int Py_EQ
49
 
    int Py_NE
50
49
    int Py_LT
51
50
    int PyObject_RichCompareBool(object, object, int opid) except -1
52
51
    int PyObject_RichCompareBool_ptr "PyObject_RichCompareBool" (
144
143
        cache_key = (ann_two, ann_one)
145
144
    temp = PyDict_GetItem(cache, cache_key)
146
145
    if temp != NULL:
147
 
        _update_counter('combine cache hit', 1)
148
146
        return <object>temp
149
147
 
150
148
    if not PyTuple_CheckExact(ann_one) or not PyTuple_CheckExact(ann_two):
222
220
                    self._num_needed_children[parent_key] += 1
223
221
                else:
224
222
                    self._num_needed_children[parent_key] = 1
225
 
                _update_counter('num children', 1)
 
223
                # _update_counter('num children', 1)
226
224
        self._parent_map.update(parent_map)
227
225
        # _heads_provider does some graph caching, so it is only valid while
228
226
        # self._parent_map hasn't changed
260
258
        parent_lines = self._text_cache[parent_key]
261
259
        parent_annotations = self._annotations_cache[parent_key]
262
260
        # PatienceSequenceMatcher should probably be part of Policy
263
 
        t = c()
 
261
        # t = c()
264
262
        matcher = patiencediff.PatienceSequenceMatcher(None,
265
263
            parent_lines, text)
266
264
        matching_blocks = matcher.get_matching_blocks()
267
 
        _update_counter('get_matching_blocks()', c() - t)
 
265
        # _update_counter('get_matching_blocks()', c() - t)
268
266
        return parent_annotations, matching_blocks
269
267
 
270
268
    def _pyx_update_from_one_parent(self, key, annotations, lines, parent_key):
300
298
        """Reannotate this text relative to a second (or more) parent."""
301
299
        cdef Py_ssize_t parent_idx, ann_idx, lines_idx, match_len, idx
302
300
        cdef Py_ssize_t pos
303
 
        cdef PyObject *temp
 
301
        cdef PyObject *temp, *ann_temp, *par_temp
304
302
        t1 = c()
305
303
        parent_annotations, matching_blocks = self._get_parent_annotations_and_matches(
306
304
            key, lines, parent_key)
318
316
            # this parent wins over the current annotation
319
317
            for idx from 0 <= idx < match_len:
320
318
                ann_idx = lines_idx + idx
321
 
                temp = PyList_GET_ITEM(annotations, ann_idx)
322
 
                ann = <object>temp
323
 
                temp = PyList_GET_ITEM(parent_annotations, parent_idx + idx)
324
 
                par_ann = <object>temp
325
 
                if (PyObject_RichCompareBool(ann, par_ann, Py_EQ)):
326
 
                    # Nothing to change
 
319
                ann_temp = PyList_GET_ITEM(annotations, ann_idx)
 
320
                par_temp = PyList_GET_ITEM(parent_annotations, parent_idx + idx)
 
321
                if (ann_temp == par_temp):
 
322
                    # This is parent, do nothing
 
323
                    # Pointer comparison is fine here. Value comparison would
 
324
                    # be ok, but it will be handled in the final if clause by
 
325
                    # merging the two tuples into the same tuple
 
326
                    # Avoiding the Py_INCREF by using pointer comparison drops
 
327
                    # timing from 215ms => 125ms
327
328
                    continue
328
 
                if (PyObject_RichCompareBool(ann, this_annotation, Py_EQ)):
 
329
                par_ann = <object>par_temp
 
330
                ann = <object>ann_temp
 
331
                if (ann is this_annotation):
329
332
                    # Originally claimed 'this', but it was really in this
330
333
                    # parent
331
334
                    Py_INCREF(par_ann)
333
336
                    continue
334
337
                # Resolve the fact that both sides have a different value for
335
338
                # last modified
336
 
                if (PyObject_RichCompareBool(ann, last_ann, Py_EQ)
337
 
                    and PyObject_RichCompareBool(par_ann, last_parent, Py_EQ)):
 
339
                if (ann is last_ann and par_ann is last_parent):
338
340
                    Py_INCREF(last_res)
339
341
                    PyList_SetItem(annotations, ann_idx, last_res)
340
342
                else:
341
 
                    _update_counter('combined annotations', 1)
342
 
                    t = c()
343
343
                    new_ann = _combine_annotations(ann, par_ann, cache)
344
 
                    _update_counter('combining annotations', c() - t)
345
344
                    Py_INCREF(new_ann)
346
345
                    PyList_SetItem(annotations, ann_idx, new_ann)
347
346
                    last_ann = ann