~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_pyx.pyx

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
 
24
24
cdef extern from "Python.h":
 
25
    ctypedef struct PyObject:
 
26
        pass
25
27
    ctypedef int Py_ssize_t # Required for older pyrex versions
26
28
    int PyString_CheckExact(object)
27
29
    char * PyString_AS_STRING(object)
53
55
             unsigned long *delta_size, unsigned long max_delta_size) nogil
54
56
    unsigned long get_delta_hdr_size(unsigned char **datap,
55
57
                                     unsigned char *top) nogil
 
58
    unsigned long sizeof_delta_index(delta_index *index)
56
59
    Py_ssize_t DELTA_SIZE_MIN
57
60
 
58
61
 
91
94
    cdef readonly object _sources
92
95
    cdef source_info *_source_infos
93
96
    cdef delta_index *_index
 
97
    cdef public unsigned long _source_offset
94
98
    cdef readonly unsigned int _max_num_sources
95
 
    cdef public unsigned long _source_offset
96
99
 
97
100
    def __init__(self, source=None):
98
101
        self._sources = []
105
108
        if source is not None:
106
109
            self.add_source(source, 0)
107
110
 
 
111
    def __sizeof__(self):
 
112
        # We want to track the _source_infos allocations, but the referenced
 
113
        # void* are actually tracked in _sources itself.
 
114
        # XXX: Cython is capable of doing sizeof(class) and returning the size
 
115
        #      of the underlying struct. Pyrex (<= 0.9.9) refuses, so we need
 
116
        #      to do it manually. *sigh* Note that we might get it wrong
 
117
        #      because of alignment issues.
 
118
        cdef Py_ssize_t size
 
119
        # PyObject start, vtable *, 3 object pointers, 2 C ints
 
120
        size = ((sizeof(PyObject) + sizeof(void*) + 3*sizeof(PyObject*)
 
121
                 + sizeof(unsigned long)
 
122
                 + sizeof(unsigned int))
 
123
                + (sizeof(source_info) * self._max_num_sources)
 
124
                + sizeof_delta_index(self._index))
 
125
        return size
 
126
 
108
127
    def __repr__(self):
109
128
        return '%s(%d, %d)' % (self.__class__.__name__,
110
129
            len(self._sources), self._source_offset)