~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_btree_serializer_pyx.pyx

  • Committer: Martin Pool
  • Date: 2009-09-14 01:48:28 UTC
  • mfrom: (4685 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4688.
  • Revision ID: mbp@sourcefrog.net-20090914014828-ydr9rlkdfq2sv57z
Merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
41
41
    int PyString_AsStringAndSize_ptr(PyObject *, char **buf, Py_ssize_t *len)
42
42
    void PyString_InternInPlace(PyObject **)
43
43
    int PyTuple_CheckExact(object t)
 
44
    object PyTuple_New(Py_ssize_t n_entries)
 
45
    void PyTuple_SET_ITEM(object, Py_ssize_t offset, object) # steals the ref
44
46
    Py_ssize_t PyTuple_GET_SIZE(object t)
45
47
    PyObject *PyTuple_GET_ITEM_ptr_object "PyTuple_GET_ITEM" (object tpl, int index)
 
48
    void Py_INCREF(object)
46
49
    void Py_DECREF_ptr "Py_DECREF" (PyObject *)
47
50
 
48
51
cdef extern from "string.h":
140
143
        cdef char *temp_ptr
141
144
        cdef int loop_counter
142
145
        # keys are tuples
143
 
        loop_counter = 0
144
 
        key_segments = []
145
 
        while loop_counter < self.key_length:
146
 
            loop_counter = loop_counter + 1
 
146
        key = PyTuple_New(self.key_length)
 
147
        for loop_counter from 0 <= loop_counter < self.key_length:
147
148
            # grab a key segment
148
149
            temp_ptr = <char*>memchr(self._start, c'\0', last - self._start)
149
150
            if temp_ptr == NULL:
150
 
                if loop_counter == self.key_length:
 
151
                if loop_counter + 1 == self.key_length:
151
152
                    # capture to last
152
153
                    temp_ptr = last
153
154
                else:
164
165
                                                         temp_ptr - self._start)
165
166
            # advance our pointer
166
167
            self._start = temp_ptr + 1
167
 
            PyList_Append(key_segments, key_element)
168
 
        return tuple(key_segments)
 
168
            Py_INCREF(key_element)
 
169
            PyTuple_SET_ITEM(key, loop_counter, key_element)
 
170
        return key
169
171
 
170
172
    cdef int process_line(self) except -1:
171
173
        """Process a line in the bytes."""