17
17
"""Functionality for doing annotations in the 'optimal' way"""
19
20
cdef extern from "python-compat.h":
23
from cpython.dict cimport (
27
from cpython.list cimport (
35
from cpython.object cimport (
39
PyObject_RichCompareBool,
41
from cpython.ref cimport (
44
from cpython.tuple cimport (
22
52
cdef extern from "Python.h":
23
ctypedef int Py_ssize_t
24
ctypedef struct PyObject:
26
53
ctypedef struct PyListObject:
28
int PyList_CheckExact(object)
29
PyObject *PyList_GET_ITEM(object, Py_ssize_t o)
30
Py_ssize_t PyList_GET_SIZE(object)
31
int PyList_Append(object, object) except -1
32
int PyList_SetItem(object, Py_ssize_t o, object) except -1
33
int PyList_Sort(object) except -1
35
int PyTuple_CheckExact(object)
36
object PyTuple_New(Py_ssize_t len)
37
void PyTuple_SET_ITEM(object, Py_ssize_t pos, object)
38
56
void PyTuple_SET_ITEM_ptr "PyTuple_SET_ITEM" (object, Py_ssize_t,
40
int PyTuple_Resize(PyObject **, Py_ssize_t newlen)
41
PyObject *PyTuple_GET_ITEM(object, Py_ssize_t o)
42
Py_ssize_t PyTuple_GET_SIZE(object)
44
PyObject *PyDict_GetItem(object d, object k)
45
int PyDict_SetItem(object d, object k, object v) except -1
47
void Py_INCREF(object)
48
59
void Py_INCREF_ptr "Py_INCREF" (PyObject *)
49
60
void Py_DECREF_ptr "Py_DECREF" (PyObject *)
53
int PyObject_RichCompareBool(object, object, int opid) except -1
54
62
int PyObject_RichCompareBool_ptr "PyObject_RichCompareBool" (
55
63
PyObject *, PyObject *, int opid)
58
from bzrlib import _annotator_py
66
from . import _annotator_py
61
69
cdef int _check_annotations_are_lists(annotations,
101
109
"""Combine the annotations from both sides."""
102
110
cdef Py_ssize_t pos_one, pos_two, len_one, len_two
103
111
cdef Py_ssize_t out_pos
104
cdef PyObject *temp, *left, *right
106
116
if (PyObject_RichCompareBool(ann_one, ann_two, Py_LT)):
107
117
cache_key = (ann_one, ann_two)
168
178
matching_blocks defines the ranges that match.
170
180
cdef Py_ssize_t parent_idx, lines_idx, match_len, idx
171
cdef PyListObject *par_list, *ann_list
172
cdef PyObject **par_temp, **ann_temp
181
cdef PyListObject *par_list
182
cdef PyListObject *ann_list
183
cdef PyObject **par_temp
184
cdef PyObject **ann_temp
174
186
_check_annotations_are_lists(annotations, parent_annotations)
175
187
par_list = <PyListObject *>parent_annotations
176
188
ann_list = <PyListObject *>annotations
177
# For NEWS and bzrlib/builtins.py, over 99% of the lines are simply copied
189
# For NEWS and breezy/builtins.py, over 99% of the lines are simply copied
178
190
# across from the parent entry. So this routine is heavily optimized for
179
191
# that. Would be interesting if we could use memcpy() but we have to incref
194
206
matching_blocks, ann_cache) except -1:
195
207
cdef Py_ssize_t parent_idx, ann_idx, lines_idx, match_len, idx
196
208
cdef Py_ssize_t pos
197
cdef PyObject *ann_temp, *par_temp
209
cdef PyObject *ann_temp
210
cdef PyObject *par_temp
199
212
_check_annotations_are_lists(annotations, parent_annotations)