~ubuntu-branches/ubuntu/vivid/bzr/vivid

« back to all changes in this revision

Viewing changes to bzrlib/_btree_serializer_pyx.c

  • Committer: Jelmer Vernooij
  • Date: 2012-02-25 15:54:11 UTC
  • mfrom: (3930.3.71 unstable-2.5)
  • Revision ID: jelmer@samba.org-20120225155411-7nkz73y3xmshn2n8
Tags: 2.5.0-1ubuntu1
releasing version 2.5.0-1ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Generated by Cython 0.14.1 on Mon Jan 16 15:59:41 2012 */
 
2
 
 
3
#define PY_SSIZE_T_CLEAN
 
4
#include "Python.h"
 
5
#ifndef Py_PYTHON_H
 
6
    #error Python headers needed to compile C extensions, please install development version of Python.
 
7
#else
 
8
 
 
9
#include <stddef.h> /* For offsetof */
 
10
#ifndef offsetof
 
11
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
 
12
#endif
 
13
 
 
14
#if !defined(WIN32) && !defined(MS_WINDOWS)
 
15
  #ifndef __stdcall
 
16
    #define __stdcall
 
17
  #endif
 
18
  #ifndef __cdecl
 
19
    #define __cdecl
 
20
  #endif
 
21
  #ifndef __fastcall
 
22
    #define __fastcall
 
23
  #endif
 
24
#endif
 
25
 
 
26
#ifndef DL_IMPORT
 
27
  #define DL_IMPORT(t) t
 
28
#endif
 
29
#ifndef DL_EXPORT
 
30
  #define DL_EXPORT(t) t
 
31
#endif
 
32
 
 
33
#ifndef PY_LONG_LONG
 
34
  #define PY_LONG_LONG LONG_LONG
 
35
#endif
 
36
 
 
37
#if PY_VERSION_HEX < 0x02040000
 
38
  #define METH_COEXIST 0
 
39
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
 
40
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
 
41
#endif
 
42
 
 
43
#if PY_VERSION_HEX < 0x02050000
 
44
  typedef int Py_ssize_t;
 
45
  #define PY_SSIZE_T_MAX INT_MAX
 
46
  #define PY_SSIZE_T_MIN INT_MIN
 
47
  #define PY_FORMAT_SIZE_T ""
 
48
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
 
49
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
 
50
  #define PyNumber_Index(o)    PyNumber_Int(o)
 
51
  #define PyIndex_Check(o)     PyNumber_Check(o)
 
52
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
 
53
#endif
 
54
 
 
55
#if PY_VERSION_HEX < 0x02060000
 
56
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
 
57
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
 
58
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
 
59
  #define PyVarObject_HEAD_INIT(type, size) \
 
60
          PyObject_HEAD_INIT(type) size,
 
61
  #define PyType_Modified(t)
 
62
 
 
63
  typedef struct {
 
64
     void *buf;
 
65
     PyObject *obj;
 
66
     Py_ssize_t len;
 
67
     Py_ssize_t itemsize;
 
68
     int readonly;
 
69
     int ndim;
 
70
     char *format;
 
71
     Py_ssize_t *shape;
 
72
     Py_ssize_t *strides;
 
73
     Py_ssize_t *suboffsets;
 
74
     void *internal;
 
75
  } Py_buffer;
 
76
 
 
77
  #define PyBUF_SIMPLE 0
 
78
  #define PyBUF_WRITABLE 0x0001
 
79
  #define PyBUF_FORMAT 0x0004
 
80
  #define PyBUF_ND 0x0008
 
81
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
 
82
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
 
83
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
 
84
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
 
85
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
 
86
 
 
87
#endif
 
88
 
 
89
#if PY_MAJOR_VERSION < 3
 
90
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
 
91
#else
 
92
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
 
93
#endif
 
94
 
 
95
#if PY_MAJOR_VERSION >= 3
 
96
  #define Py_TPFLAGS_CHECKTYPES 0
 
97
  #define Py_TPFLAGS_HAVE_INDEX 0
 
98
#endif
 
99
 
 
100
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
 
101
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
 
102
#endif
 
103
 
 
104
#if PY_MAJOR_VERSION >= 3
 
105
  #define PyBaseString_Type            PyUnicode_Type
 
106
  #define PyStringObject               PyUnicodeObject
 
107
  #define PyString_Type                PyUnicode_Type
 
108
  #define PyString_Check               PyUnicode_Check
 
109
  #define PyString_CheckExact          PyUnicode_CheckExact
 
110
#endif
 
111
 
 
112
#if PY_VERSION_HEX < 0x02060000
 
113
  #define PyBytesObject                PyStringObject
 
114
  #define PyBytes_Type                 PyString_Type
 
115
  #define PyBytes_Check                PyString_Check
 
116
  #define PyBytes_CheckExact           PyString_CheckExact
 
117
  #define PyBytes_FromString           PyString_FromString
 
118
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
 
119
  #define PyBytes_FromFormat           PyString_FromFormat
 
120
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
 
121
  #define PyBytes_AsString             PyString_AsString
 
122
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
 
123
  #define PyBytes_Size                 PyString_Size
 
124
  #define PyBytes_AS_STRING            PyString_AS_STRING
 
125
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
 
126
  #define PyBytes_Repr                 PyString_Repr
 
127
  #define PyBytes_Concat               PyString_Concat
 
128
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
 
129
#endif
 
130
 
 
131
#if PY_VERSION_HEX < 0x02060000
 
132
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
 
133
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
 
134
#endif
 
135
#ifndef PySet_CheckExact
 
136
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
 
137
#endif
 
138
 
 
139
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
 
140
 
 
141
#if PY_MAJOR_VERSION >= 3
 
142
  #define PyIntObject                  PyLongObject
 
143
  #define PyInt_Type                   PyLong_Type
 
144
  #define PyInt_Check(op)              PyLong_Check(op)
 
145
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
 
146
  #define PyInt_FromString             PyLong_FromString
 
147
  #define PyInt_FromUnicode            PyLong_FromUnicode
 
148
  #define PyInt_FromLong               PyLong_FromLong
 
149
  #define PyInt_FromSize_t             PyLong_FromSize_t
 
150
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
 
151
  #define PyInt_AsLong                 PyLong_AsLong
 
152
  #define PyInt_AS_LONG                PyLong_AS_LONG
 
153
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
 
154
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
 
155
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
 
156
#endif
 
157
 
 
158
#if PY_MAJOR_VERSION >= 3
 
159
  #define PyBoolObject                 PyLongObject
 
160
#endif
 
161
 
 
162
 
 
163
#if PY_MAJOR_VERSION >= 3
 
164
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
 
165
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
 
166
#else
 
167
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
 
168
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
 
169
#endif
 
170
 
 
171
#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
 
172
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
 
173
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
 
174
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
 
175
#else
 
176
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
 
177
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
 
178
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
 
179
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
 
180
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
 
181
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
 
182
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
 
183
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
 
184
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
 
185
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
 
186
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
 
187
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
 
188
#endif
 
189
 
 
190
#if PY_MAJOR_VERSION >= 3
 
191
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
 
192
#endif
 
193
 
 
194
#if PY_VERSION_HEX < 0x02050000
 
195
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
 
196
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
 
197
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
 
198
#else
 
199
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
 
200
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
 
201
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
 
202
#endif
 
203
 
 
204
#if PY_VERSION_HEX < 0x02050000
 
205
  #define __Pyx_NAMESTR(n) ((char *)(n))
 
206
  #define __Pyx_DOCSTR(n)  ((char *)(n))
 
207
#else
 
208
  #define __Pyx_NAMESTR(n) (n)
 
209
  #define __Pyx_DOCSTR(n)  (n)
 
210
#endif
 
211
 
 
212
#ifdef __cplusplus
 
213
#define __PYX_EXTERN_C extern "C"
 
214
#else
 
215
#define __PYX_EXTERN_C extern
 
216
#endif
 
217
 
 
218
#if defined(WIN32) || defined(MS_WINDOWS)
 
219
#define _USE_MATH_DEFINES
 
220
#endif
 
221
#include <math.h>
 
222
#define __PYX_HAVE_API__bzrlib___btree_serializer_pyx
 
223
#include "python-compat.h"
 
224
#include "stdlib.h"
 
225
#include "string.h"
 
226
#include "_static_tuple_c.h"
 
227
 
 
228
#ifdef PYREX_WITHOUT_ASSERTIONS
 
229
#define CYTHON_WITHOUT_ASSERTIONS
 
230
#endif
 
231
 
 
232
 
 
233
/* inline attribute */
 
234
#ifndef CYTHON_INLINE
 
235
  #if defined(__GNUC__)
 
236
    #define CYTHON_INLINE __inline__
 
237
  #elif defined(_MSC_VER)
 
238
    #define CYTHON_INLINE __inline
 
239
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
 
240
    #define CYTHON_INLINE inline
 
241
  #else
 
242
    #define CYTHON_INLINE
 
243
  #endif
 
244
#endif
 
245
 
 
246
/* unused attribute */
 
247
#ifndef CYTHON_UNUSED
 
248
# if defined(__GNUC__)
 
249
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
 
250
#     define CYTHON_UNUSED __attribute__ ((__unused__))
 
251
#   else
 
252
#     define CYTHON_UNUSED
 
253
#   endif
 
254
# elif defined(__ICC) || defined(__INTEL_COMPILER)
 
255
#   define CYTHON_UNUSED __attribute__ ((__unused__))
 
256
# else
 
257
#   define CYTHON_UNUSED
 
258
# endif
 
259
#endif
 
260
 
 
261
typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
 
262
 
 
263
 
 
264
/* Type Conversion Predeclarations */
 
265
 
 
266
#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
 
267
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))
 
268
 
 
269
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
 
270
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
 
271
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
 
272
 
 
273
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
 
274
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
 
275
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
 
276
 
 
277
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
 
278
 
 
279
 
 
280
#ifdef __GNUC__
 
281
/* Test for GCC > 2.95 */
 
282
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
 
283
#define likely(x)   __builtin_expect(!!(x), 1)
 
284
#define unlikely(x) __builtin_expect(!!(x), 0)
 
285
#else /* __GNUC__ > 2 ... */
 
286
#define likely(x)   (x)
 
287
#define unlikely(x) (x)
 
288
#endif /* __GNUC__ > 2 ... */
 
289
#else /* __GNUC__ */
 
290
#define likely(x)   (x)
 
291
#define unlikely(x) (x)
 
292
#endif /* __GNUC__ */
 
293
    
 
294
static PyObject *__pyx_m;
 
295
static PyObject *__pyx_b;
 
296
static PyObject *__pyx_empty_tuple;
 
297
static PyObject *__pyx_empty_bytes;
 
298
static int __pyx_lineno;
 
299
static int __pyx_clineno = 0;
 
300
static const char * __pyx_cfilenm= __FILE__;
 
301
static const char *__pyx_filename;
 
302
 
 
303
 
 
304
static const char *__pyx_f[] = {
 
305
  "_btree_serializer_pyx.pyx",
 
306
  "_static_tuple_c.pxd",
 
307
};
 
308
 
 
309
/* Type declarations */
 
310
 
 
311
/* "bzrlib/_btree_serializer_pyx.pyx":337
 
312
 * #       One slightly ugly option would be to cache block offsets in a global.
 
313
 * #       However, that leads to thread-safety issues, etc.
 
314
 * ctypedef struct gc_chk_sha1_record:             # <<<<<<<<<<<<<<
 
315
 *     long long block_offset
 
316
 *     unsigned int block_length
 
317
 */
 
318
 
 
319
typedef struct {
 
320
  PY_LONG_LONG block_offset;
 
321
  unsigned int block_length;
 
322
  unsigned int record_start;
 
323
  unsigned int record_end;
 
324
  char sha1[20];
 
325
} __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record;
 
326
 
 
327
/* "bzrlib/_btree_serializer_pyx.pyx":123
 
328
 * 
 
329
 * 
 
330
 * cdef class BTreeLeafParser:             # <<<<<<<<<<<<<<
 
331
 *     """Parse the leaf nodes of a BTree index.
 
332
 * 
 
333
 */
 
334
 
 
335
struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser {
 
336
  PyObject_HEAD
 
337
  struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_vtab;
 
338
  PyObject *bytes;
 
339
  int key_length;
 
340
  int ref_list_length;
 
341
  PyObject *keys;
 
342
  char *_cur_str;
 
343
  char *_end_str;
 
344
  char *_start;
 
345
  int _header_found;
 
346
};
 
347
 
 
348
/* "bzrlib/_btree_serializer_pyx.pyx":518
 
349
 * 
 
350
 * 
 
351
 * cdef class GCCHKSHA1LeafNode:             # <<<<<<<<<<<<<<
 
352
 *     """Track all the entries for a given leaf node."""
 
353
 * 
 
354
 */
 
355
 
 
356
struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode {
 
357
  PyObject_HEAD
 
358
  struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_vtab;
 
359
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *records;
 
360
  PyObject *last_key;
 
361
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *last_record;
 
362
  int num_records;
 
363
  unsigned char common_shift;
 
364
  unsigned char offsets[257];
 
365
};
 
366
 
 
367
 
 
368
struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode {
 
369
  StaticTuple *(*_record_to_value_and_refs)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *);
 
370
  StaticTuple *(*_record_to_item)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *);
 
371
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *(*_lookup_record)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *);
 
372
  int (*_count_records)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *, char *);
 
373
  PyObject *(*_parse_bytes)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, PyObject *);
 
374
  char *(*_parse_one_entry)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *, char *, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *);
 
375
  int (*_offset_for_sha1)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *);
 
376
  PyObject *(*_compute_common)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *);
 
377
};
 
378
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
 
379
 
 
380
 
 
381
/* "bzrlib/_btree_serializer_pyx.pyx":123
 
382
 * 
 
383
 * 
 
384
 * cdef class BTreeLeafParser:             # <<<<<<<<<<<<<<
 
385
 *     """Parse the leaf nodes of a BTree index.
 
386
 * 
 
387
 */
 
388
 
 
389
struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser {
 
390
  PyObject *(*extract_key)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *, char *);
 
391
  int (*process_line)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *);
 
392
};
 
393
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
 
394
 
 
395
#ifndef CYTHON_REFNANNY
 
396
  #define CYTHON_REFNANNY 0
 
397
#endif
 
398
 
 
399
#if CYTHON_REFNANNY
 
400
  typedef struct {
 
401
    void (*INCREF)(void*, PyObject*, int);
 
402
    void (*DECREF)(void*, PyObject*, int);
 
403
    void (*GOTREF)(void*, PyObject*, int);
 
404
    void (*GIVEREF)(void*, PyObject*, int);
 
405
    void* (*SetupContext)(const char*, int, const char*);
 
406
    void (*FinishContext)(void**);
 
407
  } __Pyx_RefNannyAPIStruct;
 
408
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
 
409
  static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
 
410
    PyObject *m = NULL, *p = NULL;
 
411
    void *r = NULL;
 
412
    m = PyImport_ImportModule((char *)modname);
 
413
    if (!m) goto end;
 
414
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
 
415
    if (!p) goto end;
 
416
    r = PyLong_AsVoidPtr(p);
 
417
  end:
 
418
    Py_XDECREF(p);
 
419
    Py_XDECREF(m);
 
420
    return (__Pyx_RefNannyAPIStruct *)r;
 
421
  }
 
422
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
 
423
  #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
 
424
  #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
 
425
  #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
 
426
  #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
 
427
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
 
428
  #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
 
429
#else
 
430
  #define __Pyx_RefNannySetupContext(name)
 
431
  #define __Pyx_RefNannyFinishContext()
 
432
  #define __Pyx_INCREF(r) Py_INCREF(r)
 
433
  #define __Pyx_DECREF(r) Py_DECREF(r)
 
434
  #define __Pyx_GOTREF(r)
 
435
  #define __Pyx_GIVEREF(r)
 
436
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
 
437
#endif /* CYTHON_REFNANNY */
 
438
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
 
439
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)
 
440
 
 
441
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
 
442
 
 
443
static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
 
444
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
 
445
 
 
446
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
 
447
 
 
448
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
 
449
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
 
450
 
 
451
static void __Pyx_RaiseDoubleKeywordsError(
 
452
    const char* func_name, PyObject* kw_name); /*proto*/
 
453
 
 
454
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/
 
455
 
 
456
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
 
457
 
 
458
static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */
 
459
 
 
460
 
 
461
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
 
462
    PyObject *r;
 
463
    if (!j) return NULL;
 
464
    r = PyObject_GetItem(o, j);
 
465
    Py_DECREF(j);
 
466
    return r;
 
467
}
 
468
 
 
469
 
 
470
#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
 
471
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
 
472
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
 
473
 
 
474
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
 
475
    if (likely(o != Py_None)) {
 
476
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
 
477
            PyObject *r = PyList_GET_ITEM(o, i);
 
478
            Py_INCREF(r);
 
479
            return r;
 
480
        }
 
481
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
 
482
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
 
483
            Py_INCREF(r);
 
484
            return r;
 
485
        }
 
486
    }
 
487
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
 
488
}
 
489
 
 
490
#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
 
491
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
 
492
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
 
493
 
 
494
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
 
495
    if (likely(o != Py_None)) {
 
496
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
 
497
            PyObject *r = PyTuple_GET_ITEM(o, i);
 
498
            Py_INCREF(r);
 
499
            return r;
 
500
        }
 
501
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
 
502
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
 
503
            Py_INCREF(r);
 
504
            return r;
 
505
        }
 
506
    }
 
507
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
 
508
}
 
509
 
 
510
 
 
511
#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
 
512
                                                    __Pyx_GetItemInt_Fast(o, i) : \
 
513
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))
 
514
 
 
515
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
 
516
    PyObject *r;
 
517
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
 
518
        r = PyList_GET_ITEM(o, i);
 
519
        Py_INCREF(r);
 
520
    }
 
521
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
 
522
        r = PyTuple_GET_ITEM(o, i);
 
523
        Py_INCREF(r);
 
524
    }
 
525
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
 
526
        r = PySequence_GetItem(o, i);
 
527
    }
 
528
    else {
 
529
        r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
 
530
    }
 
531
    return r;
 
532
}
 
533
 
 
534
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
 
535
 
 
536
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
 
537
 
 
538
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
 
539
 
 
540
static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
 
541
 
 
542
static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
 
543
 
 
544
static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
 
545
 
 
546
static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
 
547
 
 
548
static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
 
549
 
 
550
static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
 
551
 
 
552
static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
 
553
 
 
554
static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
 
555
 
 
556
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
 
557
 
 
558
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
 
559
 
 
560
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
 
561
 
 
562
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
 
563
 
 
564
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
 
565
 
 
566
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
 
567
 
 
568
static void __Pyx_WriteUnraisable(const char *name); /*proto*/
 
569
 
 
570
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
 
571
 
 
572
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict);  /*proto*/
 
573
 
 
574
static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
 
575
 
 
576
static void __Pyx_AddTraceback(const char *funcname); /*proto*/
 
577
 
 
578
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
 
579
/* Module declarations from bzrlib._static_tuple_c */
 
580
 
 
581
/* Module declarations from bzrlib._static_tuple_c */
 
582
 
 
583
static PyTypeObject *__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple = 0;
 
584
/* Module declarations from bzrlib._btree_serializer_pyx */
 
585
 
 
586
static PyTypeObject *__pyx_ptype_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = 0;
 
587
static PyTypeObject *__pyx_ptype_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = 0;
 
588
static int __pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[256];
 
589
static char *__pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf;
 
590
static void *__pyx_f_6bzrlib_21_btree_serializer_pyx__my_memrchr(void *, int, size_t); /*proto*/
 
591
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(char *, Py_ssize_t); /*proto*/
 
592
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size(char *, Py_ssize_t); /*proto*/
 
593
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__populate_unhexbuf(void); /*proto*/
 
594
static int __pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(char *, char *); /*proto*/
 
595
static void __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(char *, char *); /*proto*/
 
596
static int __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(PyObject *, char *); /*proto*/
 
597
static StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(char *); /*proto*/
 
598
static unsigned int __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint(char *); /*proto*/
 
599
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__format_record(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *); /*proto*/
 
600
#define __Pyx_MODULE_NAME "bzrlib._btree_serializer_pyx"
 
601
static int __pyx_module_is_main_bzrlib___btree_serializer_pyx = 0;
 
602
 
 
603
/* Implementation of bzrlib._btree_serializer_pyx */
 
604
static PyObject *__pyx_builtin_AssertionError;
 
605
static PyObject *__pyx_builtin_ValueError;
 
606
static PyObject *__pyx_builtin_KeyError;
 
607
static PyObject *__pyx_builtin_TypeError;
 
608
static char __pyx_k_1[] = "tried to create a string with an invalid size: %d @0x%x";
 
609
static char __pyx_k_2[] = "invalid key, wanted segment from ";
 
610
static char __pyx_k_3[] = "sha1:";
 
611
static char __pyx_k_4[] = "last < self._start";
 
612
static char __pyx_k_6[] = "type=leaf";
 
613
static char __pyx_k_7[] = "Node did not start with \"type=leaf\": %r";
 
614
static char __pyx_k_8[] = "Failed to find the value area";
 
615
static char __pyx_k_10[] = " 0 0";
 
616
static char __pyx_k_12[] = "invalid key, loop_counter != self.ref_list_length";
 
617
static char __pyx_k_14[] = "unexpected reference data present";
 
618
static char __pyx_k_16[] = "self.bytes is not a string.";
 
619
static char __pyx_k_18[] = "not a 40-byte hex digest";
 
620
static char __pyx_k_20[] = "not a 20-byte binary digest";
 
621
static char __pyx_k_22[] = "sha1_bin must be a str of exactly 20 bytes";
 
622
static char __pyx_k_24[] = "%s %u %u %u";
 
623
static char __pyx_k_25[] = "%lu %u %u %u";
 
624
static char __pyx_k_26[] = "_record_to_value_and_refs";
 
625
static char __pyx_k_27[] = "key %r is not present";
 
626
static char __pyx_k_28[] = "We only support parsing plain 8-bit strings.";
 
627
static char __pyx_k_30[] = "type=leaf\n";
 
628
static char __pyx_k_31[] = "bytes did not start with 'type=leaf\\n': %r";
 
629
static char __pyx_k_32[] = "Something went wrong while parsing.";
 
630
static char __pyx_k_34[] = "line did not start with sha1: %r";
 
631
static char __pyx_k_35[] = "Line did not contain 40 hex bytes";
 
632
static char __pyx_k_37[] = "We failed to unhexlify";
 
633
static char __pyx_k_39[] = "only 1 null, not 2 as expected";
 
634
static char __pyx_k_41[] = "Failed to parse block offset";
 
635
static char __pyx_k_43[] = "Failed to parse block length";
 
636
static char __pyx_k_46[] = "Failed to parse record end";
 
637
static char __pyx_k_48[] = "We expected a tuple() or StaticTuple() for node not: %s";
 
638
static char __pyx_k_49[] = "With ref_lists, we expected 4 entries not: %s";
 
639
static char __pyx_k_50[] = "Without ref_lists, we need at least 3 entries not: %s";
 
640
static char __pyx_k_51[] = "\000";
 
641
static char __pyx_k_52[] = "We expect references to be tuples not: %s";
 
642
static char __pyx_k_53[] = "We expect reference bits to be strings not: %s";
 
643
static char __pyx_k_54[] = "Expected a plain str for value not: %s";
 
644
static char __pyx_k_55[] = "Pyrex extensions to btree node parsing.";
 
645
static char __pyx_k_56[] = "bzrlib._btree_serializer_pyx";
 
646
static char __pyx_k__sys[] = "sys";
 
647
static char __pyx_k__join[] = "join";
 
648
static char __pyx_k__keys[] = "keys";
 
649
static char __pyx_k__node[] = "node";
 
650
static char __pyx_k__sha1[] = "sha1";
 
651
static char __pyx_k__bytes[] = "bytes";
 
652
static char __pyx_k__parse[] = "parse";
 
653
static char __pyx_k___start[] = "_start";
 
654
static char __pyx_k__offsets[] = "offsets";
 
655
static char __pyx_k__records[] = "records";
 
656
static char __pyx_k__KeyError[] = "KeyError";
 
657
static char __pyx_k____main__[] = "__main__";
 
658
static char __pyx_k____test__[] = "__test__";
 
659
static char __pyx_k___cur_str[] = "_cur_str";
 
660
static char __pyx_k___end_str[] = "_end_str";
 
661
static char __pyx_k__last_key[] = "last_key";
 
662
static char __pyx_k__TypeError[] = "TypeError";
 
663
static char __pyx_k__ValueError[] = "ValueError";
 
664
static char __pyx_k__key_length[] = "key_length";
 
665
static char __pyx_k__record_end[] = "record_end";
 
666
static char __pyx_k___py_hexlify[] = "_py_hexlify";
 
667
static char __pyx_k__extract_key[] = "extract_key";
 
668
static char __pyx_k__last_record[] = "last_record";
 
669
static char __pyx_k__num_records[] = "num_records";
 
670
static char __pyx_k___parse_bytes[] = "_parse_bytes";
 
671
static char __pyx_k__block_length[] = "block_length";
 
672
static char __pyx_k__block_offset[] = "block_offset";
 
673
static char __pyx_k__common_shift[] = "common_shift";
 
674
static char __pyx_k__process_line[] = "process_line";
 
675
static char __pyx_k__record_start[] = "record_start";
 
676
static char __pyx_k___flatten_node[] = "_flatten_node";
 
677
static char __pyx_k___header_found[] = "_header_found";
 
678
static char __pyx_k___py_unhexlify[] = "_py_unhexlify";
 
679
static char __pyx_k__AssertionError[] = "AssertionError";
 
680
static char __pyx_k___count_records[] = "_count_records";
 
681
static char __pyx_k___lookup_record[] = "_lookup_record";
 
682
static char __pyx_k___compute_common[] = "_compute_common";
 
683
static char __pyx_k___parse_into_chk[] = "_parse_into_chk";
 
684
static char __pyx_k___py_key_to_sha1[] = "_py_key_to_sha1";
 
685
static char __pyx_k___py_sha1_to_key[] = "_py_sha1_to_key";
 
686
static char __pyx_k___record_to_item[] = "_record_to_item";
 
687
static char __pyx_k__ref_list_length[] = "ref_list_length";
 
688
static char __pyx_k__reference_lists[] = "reference_lists";
 
689
static char __pyx_k__0123456789abcdef[] = "0123456789abcdef";
 
690
static char __pyx_k___offset_for_sha1[] = "_offset_for_sha1";
 
691
static char __pyx_k___parse_one_entry[] = "_parse_one_entry";
 
692
static char __pyx_k___parse_leaf_lines[] = "_parse_leaf_lines";
 
693
static PyObject *__pyx_kp_s_1;
 
694
static PyObject *__pyx_kp_s_12;
 
695
static PyObject *__pyx_kp_s_14;
 
696
static PyObject *__pyx_kp_s_16;
 
697
static PyObject *__pyx_kp_s_18;
 
698
static PyObject *__pyx_kp_s_2;
 
699
static PyObject *__pyx_kp_s_20;
 
700
static PyObject *__pyx_kp_s_22;
 
701
static PyObject *__pyx_n_s_26;
 
702
static PyObject *__pyx_kp_s_27;
 
703
static PyObject *__pyx_kp_s_28;
 
704
static PyObject *__pyx_kp_s_31;
 
705
static PyObject *__pyx_kp_s_32;
 
706
static PyObject *__pyx_kp_s_34;
 
707
static PyObject *__pyx_kp_s_35;
 
708
static PyObject *__pyx_kp_s_37;
 
709
static PyObject *__pyx_kp_s_39;
 
710
static PyObject *__pyx_kp_s_4;
 
711
static PyObject *__pyx_kp_s_41;
 
712
static PyObject *__pyx_kp_s_43;
 
713
static PyObject *__pyx_kp_s_46;
 
714
static PyObject *__pyx_kp_s_48;
 
715
static PyObject *__pyx_kp_s_49;
 
716
static PyObject *__pyx_kp_s_50;
 
717
static PyObject *__pyx_kp_s_51;
 
718
static PyObject *__pyx_kp_s_52;
 
719
static PyObject *__pyx_kp_s_53;
 
720
static PyObject *__pyx_kp_s_54;
 
721
static PyObject *__pyx_n_s_56;
 
722
static PyObject *__pyx_kp_s_7;
 
723
static PyObject *__pyx_kp_s_8;
 
724
static PyObject *__pyx_n_s__AssertionError;
 
725
static PyObject *__pyx_n_s__KeyError;
 
726
static PyObject *__pyx_n_s__TypeError;
 
727
static PyObject *__pyx_n_s__ValueError;
 
728
static PyObject *__pyx_n_s____main__;
 
729
static PyObject *__pyx_n_s____test__;
 
730
static PyObject *__pyx_n_s___compute_common;
 
731
static PyObject *__pyx_n_s___count_records;
 
732
static PyObject *__pyx_n_s___cur_str;
 
733
static PyObject *__pyx_n_s___end_str;
 
734
static PyObject *__pyx_n_s___flatten_node;
 
735
static PyObject *__pyx_n_s___header_found;
 
736
static PyObject *__pyx_n_s___lookup_record;
 
737
static PyObject *__pyx_n_s___offset_for_sha1;
 
738
static PyObject *__pyx_n_s___parse_bytes;
 
739
static PyObject *__pyx_n_s___parse_into_chk;
 
740
static PyObject *__pyx_n_s___parse_leaf_lines;
 
741
static PyObject *__pyx_n_s___parse_one_entry;
 
742
static PyObject *__pyx_n_s___py_hexlify;
 
743
static PyObject *__pyx_n_s___py_key_to_sha1;
 
744
static PyObject *__pyx_n_s___py_sha1_to_key;
 
745
static PyObject *__pyx_n_s___py_unhexlify;
 
746
static PyObject *__pyx_n_s___record_to_item;
 
747
static PyObject *__pyx_n_s___start;
 
748
static PyObject *__pyx_n_s__block_length;
 
749
static PyObject *__pyx_n_s__block_offset;
 
750
static PyObject *__pyx_n_s__bytes;
 
751
static PyObject *__pyx_n_s__common_shift;
 
752
static PyObject *__pyx_n_s__extract_key;
 
753
static PyObject *__pyx_n_s__join;
 
754
static PyObject *__pyx_n_s__key_length;
 
755
static PyObject *__pyx_n_s__keys;
 
756
static PyObject *__pyx_n_s__last_key;
 
757
static PyObject *__pyx_n_s__last_record;
 
758
static PyObject *__pyx_n_s__node;
 
759
static PyObject *__pyx_n_s__num_records;
 
760
static PyObject *__pyx_n_s__offsets;
 
761
static PyObject *__pyx_n_s__parse;
 
762
static PyObject *__pyx_n_s__process_line;
 
763
static PyObject *__pyx_n_s__record_end;
 
764
static PyObject *__pyx_n_s__record_start;
 
765
static PyObject *__pyx_n_s__records;
 
766
static PyObject *__pyx_n_s__ref_list_length;
 
767
static PyObject *__pyx_n_s__reference_lists;
 
768
static PyObject *__pyx_n_s__sha1;
 
769
static PyObject *__pyx_n_s__sys;
 
770
static PyObject *__pyx_int_0;
 
771
static PyObject *__pyx_int_1;
 
772
static PyObject *__pyx_int_2147483648;
 
773
static PyObject *__pyx_int_4294967295;
 
774
static PyObject *__pyx_k_tuple_5;
 
775
static PyObject *__pyx_k_tuple_9;
 
776
static PyObject *__pyx_k_tuple_11;
 
777
static PyObject *__pyx_k_tuple_13;
 
778
static PyObject *__pyx_k_tuple_15;
 
779
static PyObject *__pyx_k_tuple_17;
 
780
static PyObject *__pyx_k_tuple_19;
 
781
static PyObject *__pyx_k_tuple_21;
 
782
static PyObject *__pyx_k_tuple_23;
 
783
static PyObject *__pyx_k_tuple_29;
 
784
static PyObject *__pyx_k_tuple_33;
 
785
static PyObject *__pyx_k_tuple_36;
 
786
static PyObject *__pyx_k_tuple_38;
 
787
static PyObject *__pyx_k_tuple_40;
 
788
static PyObject *__pyx_k_tuple_42;
 
789
static PyObject *__pyx_k_tuple_44;
 
790
static PyObject *__pyx_k_tuple_45;
 
791
static PyObject *__pyx_k_tuple_47;
 
792
 
 
793
/* "bzrlib/_btree_serializer_pyx.pyx":81
 
794
 * 
 
795
 * # TODO: Find some way to import this from _dirstate_helpers
 
796
 * cdef void* _my_memrchr(void *s, int c, size_t n): # cannot_raise             # <<<<<<<<<<<<<<
 
797
 *     # memrchr seems to be a GNU extension, so we have to implement it ourselves
 
798
 *     # It is not present in any win32 standard library
 
799
 */
 
800
 
 
801
static  void *__pyx_f_6bzrlib_21_btree_serializer_pyx__my_memrchr(void *__pyx_v_s, int __pyx_v_c, size_t __pyx_v_n) {
 
802
  char *__pyx_v_pos;
 
803
  char *__pyx_v_start;
 
804
  void *__pyx_r;
 
805
  int __pyx_t_1;
 
806
  __Pyx_RefNannySetupContext("_my_memrchr");
 
807
 
 
808
  /* "bzrlib/_btree_serializer_pyx.pyx":87
 
809
 *     cdef char *start
 
810
 * 
 
811
 *     start = <char*>s             # <<<<<<<<<<<<<<
 
812
 *     pos = start + n - 1
 
813
 *     while pos >= start:
 
814
 */
 
815
  __pyx_v_start = ((char *)__pyx_v_s);
 
816
 
 
817
  /* "bzrlib/_btree_serializer_pyx.pyx":88
 
818
 * 
 
819
 *     start = <char*>s
 
820
 *     pos = start + n - 1             # <<<<<<<<<<<<<<
 
821
 *     while pos >= start:
 
822
 *         if pos[0] == c:
 
823
 */
 
824
  __pyx_v_pos = ((__pyx_v_start + __pyx_v_n) - 1);
 
825
 
 
826
  /* "bzrlib/_btree_serializer_pyx.pyx":89
 
827
 *     start = <char*>s
 
828
 *     pos = start + n - 1
 
829
 *     while pos >= start:             # <<<<<<<<<<<<<<
 
830
 *         if pos[0] == c:
 
831
 *             return <void*>pos
 
832
 */
 
833
  while (1) {
 
834
    __pyx_t_1 = (__pyx_v_pos >= __pyx_v_start);
 
835
    if (!__pyx_t_1) break;
 
836
 
 
837
    /* "bzrlib/_btree_serializer_pyx.pyx":90
 
838
 *     pos = start + n - 1
 
839
 *     while pos >= start:
 
840
 *         if pos[0] == c:             # <<<<<<<<<<<<<<
 
841
 *             return <void*>pos
 
842
 *         pos = pos - 1
 
843
 */
 
844
    __pyx_t_1 = ((__pyx_v_pos[0]) == __pyx_v_c);
 
845
    if (__pyx_t_1) {
 
846
 
 
847
      /* "bzrlib/_btree_serializer_pyx.pyx":91
 
848
 *     while pos >= start:
 
849
 *         if pos[0] == c:
 
850
 *             return <void*>pos             # <<<<<<<<<<<<<<
 
851
 *         pos = pos - 1
 
852
 *     return NULL
 
853
 */
 
854
      __pyx_r = ((void *)__pyx_v_pos);
 
855
      goto __pyx_L0;
 
856
      goto __pyx_L5;
 
857
    }
 
858
    __pyx_L5:;
 
859
 
 
860
    /* "bzrlib/_btree_serializer_pyx.pyx":92
 
861
 *         if pos[0] == c:
 
862
 *             return <void*>pos
 
863
 *         pos = pos - 1             # <<<<<<<<<<<<<<
 
864
 *     return NULL
 
865
 * 
 
866
 */
 
867
    __pyx_v_pos = (__pyx_v_pos - 1);
 
868
  }
 
869
 
 
870
  /* "bzrlib/_btree_serializer_pyx.pyx":93
 
871
 *             return <void*>pos
 
872
 *         pos = pos - 1
 
873
 *     return NULL             # <<<<<<<<<<<<<<
 
874
 * 
 
875
 * 
 
876
 */
 
877
  __pyx_r = NULL;
 
878
  goto __pyx_L0;
 
879
 
 
880
  __pyx_r = 0;
 
881
  __pyx_L0:;
 
882
  __Pyx_RefNannyFinishContext();
 
883
  return __pyx_r;
 
884
}
 
885
 
 
886
/* "bzrlib/_btree_serializer_pyx.pyx":97
 
887
 * 
 
888
 * # TODO: Import this from _dirstate_helpers when it is merged
 
889
 * cdef object safe_string_from_size(char *s, Py_ssize_t size):             # <<<<<<<<<<<<<<
 
890
 *     if size < 0:
 
891
 *         raise AssertionError(
 
892
 */
 
893
 
 
894
static  PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(char *__pyx_v_s, Py_ssize_t __pyx_v_size) {
 
895
  PyObject *__pyx_r = NULL;
 
896
  int __pyx_t_1;
 
897
  PyObject *__pyx_t_2 = NULL;
 
898
  PyObject *__pyx_t_3 = NULL;
 
899
  PyObject *__pyx_t_4 = NULL;
 
900
  __Pyx_RefNannySetupContext("safe_string_from_size");
 
901
 
 
902
  /* "bzrlib/_btree_serializer_pyx.pyx":98
 
903
 * # TODO: Import this from _dirstate_helpers when it is merged
 
904
 * cdef object safe_string_from_size(char *s, Py_ssize_t size):
 
905
 *     if size < 0:             # <<<<<<<<<<<<<<
 
906
 *         raise AssertionError(
 
907
 *             'tried to create a string with an invalid size: %d @0x%x'
 
908
 */
 
909
  __pyx_t_1 = (__pyx_v_size < 0);
 
910
  if (__pyx_t_1) {
 
911
 
 
912
    /* "bzrlib/_btree_serializer_pyx.pyx":101
 
913
 *         raise AssertionError(
 
914
 *             'tried to create a string with an invalid size: %d @0x%x'
 
915
 *             % (size, <int>s))             # <<<<<<<<<<<<<<
 
916
 *     return PyString_FromStringAndSize(s, size)
 
917
 * 
 
918
 */
 
919
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
920
    __Pyx_GOTREF(__pyx_t_2);
 
921
    __pyx_t_3 = PyInt_FromLong(((int)__pyx_v_s)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
922
    __Pyx_GOTREF(__pyx_t_3);
 
923
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
924
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
925
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
 
926
    __Pyx_GIVEREF(__pyx_t_2);
 
927
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
 
928
    __Pyx_GIVEREF(__pyx_t_3);
 
929
    __pyx_t_2 = 0;
 
930
    __pyx_t_3 = 0;
 
931
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
932
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
933
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
934
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
935
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
936
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
 
937
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
 
938
    __pyx_t_3 = 0;
 
939
    __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
940
    __Pyx_GOTREF(__pyx_t_3);
 
941
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
942
    __Pyx_Raise(__pyx_t_3, 0, 0);
 
943
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
944
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
945
    goto __pyx_L3;
 
946
  }
 
947
  __pyx_L3:;
 
948
 
 
949
  /* "bzrlib/_btree_serializer_pyx.pyx":102
 
950
 *             'tried to create a string with an invalid size: %d @0x%x'
 
951
 *             % (size, <int>s))
 
952
 *     return PyString_FromStringAndSize(s, size)             # <<<<<<<<<<<<<<
 
953
 * 
 
954
 * 
 
955
 */
 
956
  __Pyx_XDECREF(__pyx_r);
 
957
  __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_s, __pyx_v_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
958
  __Pyx_GOTREF(__pyx_t_3);
 
959
  __pyx_r = __pyx_t_3;
 
960
  __pyx_t_3 = 0;
 
961
  goto __pyx_L0;
 
962
 
 
963
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
964
  goto __pyx_L0;
 
965
  __pyx_L1_error:;
 
966
  __Pyx_XDECREF(__pyx_t_2);
 
967
  __Pyx_XDECREF(__pyx_t_3);
 
968
  __Pyx_XDECREF(__pyx_t_4);
 
969
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.safe_string_from_size");
 
970
  __pyx_r = 0;
 
971
  __pyx_L0:;
 
972
  __Pyx_XGIVEREF(__pyx_r);
 
973
  __Pyx_RefNannyFinishContext();
 
974
  return __pyx_r;
 
975
}
 
976
 
 
977
/* "bzrlib/_btree_serializer_pyx.pyx":105
 
978
 * 
 
979
 * 
 
980
 * cdef object safe_interned_string_from_size(char *s, Py_ssize_t size):             # <<<<<<<<<<<<<<
 
981
 *     cdef PyObject *py_str
 
982
 *     if size < 0:
 
983
 */
 
984
 
 
985
static  PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size(char *__pyx_v_s, Py_ssize_t __pyx_v_size) {
 
986
  PyObject *__pyx_v_py_str;
 
987
  PyObject *__pyx_v_result;
 
988
  PyObject *__pyx_r = NULL;
 
989
  int __pyx_t_1;
 
990
  PyObject *__pyx_t_2 = NULL;
 
991
  PyObject *__pyx_t_3 = NULL;
 
992
  PyObject *__pyx_t_4 = NULL;
 
993
  __Pyx_RefNannySetupContext("safe_interned_string_from_size");
 
994
  __pyx_v_result = Py_None; __Pyx_INCREF(Py_None);
 
995
 
 
996
  /* "bzrlib/_btree_serializer_pyx.pyx":107
 
997
 * cdef object safe_interned_string_from_size(char *s, Py_ssize_t size):
 
998
 *     cdef PyObject *py_str
 
999
 *     if size < 0:             # <<<<<<<<<<<<<<
 
1000
 *         raise AssertionError(
 
1001
 *             'tried to create a string with an invalid size: %d @0x%x'
 
1002
 */
 
1003
  __pyx_t_1 = (__pyx_v_size < 0);
 
1004
  if (__pyx_t_1) {
 
1005
 
 
1006
    /* "bzrlib/_btree_serializer_pyx.pyx":110
 
1007
 *         raise AssertionError(
 
1008
 *             'tried to create a string with an invalid size: %d @0x%x'
 
1009
 *             % (size, <int>s))             # <<<<<<<<<<<<<<
 
1010
 *     py_str = PyString_FromStringAndSize_ptr(s, size)
 
1011
 *     PyString_InternInPlace(&py_str)
 
1012
 */
 
1013
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1014
    __Pyx_GOTREF(__pyx_t_2);
 
1015
    __pyx_t_3 = PyInt_FromLong(((int)__pyx_v_s)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1016
    __Pyx_GOTREF(__pyx_t_3);
 
1017
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1018
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
1019
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
 
1020
    __Pyx_GIVEREF(__pyx_t_2);
 
1021
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
 
1022
    __Pyx_GIVEREF(__pyx_t_3);
 
1023
    __pyx_t_2 = 0;
 
1024
    __pyx_t_3 = 0;
 
1025
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1026
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
1027
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
1028
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1029
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
1030
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
 
1031
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
 
1032
    __pyx_t_3 = 0;
 
1033
    __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1034
    __Pyx_GOTREF(__pyx_t_3);
 
1035
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
1036
    __Pyx_Raise(__pyx_t_3, 0, 0);
 
1037
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
1038
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1039
    goto __pyx_L3;
 
1040
  }
 
1041
  __pyx_L3:;
 
1042
 
 
1043
  /* "bzrlib/_btree_serializer_pyx.pyx":111
 
1044
 *             'tried to create a string with an invalid size: %d @0x%x'
 
1045
 *             % (size, <int>s))
 
1046
 *     py_str = PyString_FromStringAndSize_ptr(s, size)             # <<<<<<<<<<<<<<
 
1047
 *     PyString_InternInPlace(&py_str)
 
1048
 *     result = <object>py_str
 
1049
 */
 
1050
  __pyx_v_py_str = PyString_FromStringAndSize(__pyx_v_s, __pyx_v_size);
 
1051
 
 
1052
  /* "bzrlib/_btree_serializer_pyx.pyx":112
 
1053
 *             % (size, <int>s))
 
1054
 *     py_str = PyString_FromStringAndSize_ptr(s, size)
 
1055
 *     PyString_InternInPlace(&py_str)             # <<<<<<<<<<<<<<
 
1056
 *     result = <object>py_str
 
1057
 *     # Casting a PyObject* to an <object> triggers an INCREF from Pyrex, so we
 
1058
 */
 
1059
  PyString_InternInPlace((&__pyx_v_py_str));
 
1060
 
 
1061
  /* "bzrlib/_btree_serializer_pyx.pyx":113
 
1062
 *     py_str = PyString_FromStringAndSize_ptr(s, size)
 
1063
 *     PyString_InternInPlace(&py_str)
 
1064
 *     result = <object>py_str             # <<<<<<<<<<<<<<
 
1065
 *     # Casting a PyObject* to an <object> triggers an INCREF from Pyrex, so we
 
1066
 *     # DECREF it to avoid geting immortal strings
 
1067
 */
 
1068
  __Pyx_INCREF(((PyObject *)__pyx_v_py_str));
 
1069
  __Pyx_DECREF(__pyx_v_result);
 
1070
  __pyx_v_result = ((PyObject *)__pyx_v_py_str);
 
1071
 
 
1072
  /* "bzrlib/_btree_serializer_pyx.pyx":116
 
1073
 *     # Casting a PyObject* to an <object> triggers an INCREF from Pyrex, so we
 
1074
 *     # DECREF it to avoid geting immortal strings
 
1075
 *     Py_DECREF_ptr(py_str)             # <<<<<<<<<<<<<<
 
1076
 *     return result
 
1077
 * 
 
1078
 */
 
1079
  Py_DECREF(__pyx_v_py_str);
 
1080
 
 
1081
  /* "bzrlib/_btree_serializer_pyx.pyx":117
 
1082
 *     # DECREF it to avoid geting immortal strings
 
1083
 *     Py_DECREF_ptr(py_str)
 
1084
 *     return result             # <<<<<<<<<<<<<<
 
1085
 * 
 
1086
 * # This sets up the StaticTuple C_API functionality
 
1087
 */
 
1088
  __Pyx_XDECREF(__pyx_r);
 
1089
  __Pyx_INCREF(__pyx_v_result);
 
1090
  __pyx_r = __pyx_v_result;
 
1091
  goto __pyx_L0;
 
1092
 
 
1093
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
1094
  goto __pyx_L0;
 
1095
  __pyx_L1_error:;
 
1096
  __Pyx_XDECREF(__pyx_t_2);
 
1097
  __Pyx_XDECREF(__pyx_t_3);
 
1098
  __Pyx_XDECREF(__pyx_t_4);
 
1099
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.safe_interned_string_from_size");
 
1100
  __pyx_r = 0;
 
1101
  __pyx_L0:;
 
1102
  __Pyx_DECREF(__pyx_v_result);
 
1103
  __Pyx_XGIVEREF(__pyx_r);
 
1104
  __Pyx_RefNannyFinishContext();
 
1105
  return __pyx_r;
 
1106
}
 
1107
 
 
1108
/* "bzrlib/_btree_serializer_pyx.pyx":153
 
1109
 *     cdef int _header_found
 
1110
 * 
 
1111
 *     def __init__(self, bytes, key_length, ref_list_length):             # <<<<<<<<<<<<<<
 
1112
 *         self.bytes = bytes
 
1113
 *         self.key_length = key_length
 
1114
 */
 
1115
 
 
1116
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
1117
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
1118
  PyObject *__pyx_v_bytes = 0;
 
1119
  PyObject *__pyx_v_key_length = 0;
 
1120
  PyObject *__pyx_v_ref_list_length = 0;
 
1121
  int __pyx_r;
 
1122
  int __pyx_t_1;
 
1123
  PyObject *__pyx_t_2 = NULL;
 
1124
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__bytes,&__pyx_n_s__key_length,&__pyx_n_s__ref_list_length,0};
 
1125
  __Pyx_RefNannySetupContext("__init__");
 
1126
  if (unlikely(__pyx_kwds)) {
 
1127
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
 
1128
    PyObject* values[3] = {0,0,0};
 
1129
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
1130
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
 
1131
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
 
1132
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
 
1133
      case  0: break;
 
1134
      default: goto __pyx_L5_argtuple_error;
 
1135
    }
 
1136
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
1137
      case  0:
 
1138
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bytes);
 
1139
      if (likely(values[0])) kw_args--;
 
1140
      else goto __pyx_L5_argtuple_error;
 
1141
      case  1:
 
1142
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key_length);
 
1143
      if (likely(values[1])) kw_args--;
 
1144
      else {
 
1145
        __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
1146
      }
 
1147
      case  2:
 
1148
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref_list_length);
 
1149
      if (likely(values[2])) kw_args--;
 
1150
      else {
 
1151
        __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
1152
      }
 
1153
    }
 
1154
    if (unlikely(kw_args > 0)) {
 
1155
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
1156
    }
 
1157
    __pyx_v_bytes = values[0];
 
1158
    __pyx_v_key_length = values[1];
 
1159
    __pyx_v_ref_list_length = values[2];
 
1160
  } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
 
1161
    goto __pyx_L5_argtuple_error;
 
1162
  } else {
 
1163
    __pyx_v_bytes = PyTuple_GET_ITEM(__pyx_args, 0);
 
1164
    __pyx_v_key_length = PyTuple_GET_ITEM(__pyx_args, 1);
 
1165
    __pyx_v_ref_list_length = PyTuple_GET_ITEM(__pyx_args, 2);
 
1166
  }
 
1167
  goto __pyx_L4_argument_unpacking_done;
 
1168
  __pyx_L5_argtuple_error:;
 
1169
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
1170
  __pyx_L3_error:;
 
1171
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.__init__");
 
1172
  __Pyx_RefNannyFinishContext();
 
1173
  return -1;
 
1174
  __pyx_L4_argument_unpacking_done:;
 
1175
 
 
1176
  /* "bzrlib/_btree_serializer_pyx.pyx":154
 
1177
 * 
 
1178
 *     def __init__(self, bytes, key_length, ref_list_length):
 
1179
 *         self.bytes = bytes             # <<<<<<<<<<<<<<
 
1180
 *         self.key_length = key_length
 
1181
 *         self.ref_list_length = ref_list_length
 
1182
 */
 
1183
  __Pyx_INCREF(__pyx_v_bytes);
 
1184
  __Pyx_GIVEREF(__pyx_v_bytes);
 
1185
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes);
 
1186
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes);
 
1187
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes = __pyx_v_bytes;
 
1188
 
 
1189
  /* "bzrlib/_btree_serializer_pyx.pyx":155
 
1190
 *     def __init__(self, bytes, key_length, ref_list_length):
 
1191
 *         self.bytes = bytes
 
1192
 *         self.key_length = key_length             # <<<<<<<<<<<<<<
 
1193
 *         self.ref_list_length = ref_list_length
 
1194
 *         self.keys = []
 
1195
 */
 
1196
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_key_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1197
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->key_length = __pyx_t_1;
 
1198
 
 
1199
  /* "bzrlib/_btree_serializer_pyx.pyx":156
 
1200
 *         self.bytes = bytes
 
1201
 *         self.key_length = key_length
 
1202
 *         self.ref_list_length = ref_list_length             # <<<<<<<<<<<<<<
 
1203
 *         self.keys = []
 
1204
 *         self._cur_str = NULL
 
1205
 */
 
1206
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_ref_list_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1207
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->ref_list_length = __pyx_t_1;
 
1208
 
 
1209
  /* "bzrlib/_btree_serializer_pyx.pyx":157
 
1210
 *         self.key_length = key_length
 
1211
 *         self.ref_list_length = ref_list_length
 
1212
 *         self.keys = []             # <<<<<<<<<<<<<<
 
1213
 *         self._cur_str = NULL
 
1214
 *         self._end_str = NULL
 
1215
 */
 
1216
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1217
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
 
1218
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
 
1219
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys);
 
1220
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys);
 
1221
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys = ((PyObject *)__pyx_t_2);
 
1222
  __pyx_t_2 = 0;
 
1223
 
 
1224
  /* "bzrlib/_btree_serializer_pyx.pyx":158
 
1225
 *         self.ref_list_length = ref_list_length
 
1226
 *         self.keys = []
 
1227
 *         self._cur_str = NULL             # <<<<<<<<<<<<<<
 
1228
 *         self._end_str = NULL
 
1229
 *         self._header_found = 0
 
1230
 */
 
1231
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str = NULL;
 
1232
 
 
1233
  /* "bzrlib/_btree_serializer_pyx.pyx":159
 
1234
 *         self.keys = []
 
1235
 *         self._cur_str = NULL
 
1236
 *         self._end_str = NULL             # <<<<<<<<<<<<<<
 
1237
 *         self._header_found = 0
 
1238
 *         # keys are tuples
 
1239
 */
 
1240
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_end_str = NULL;
 
1241
 
 
1242
  /* "bzrlib/_btree_serializer_pyx.pyx":160
 
1243
 *         self._cur_str = NULL
 
1244
 *         self._end_str = NULL
 
1245
 *         self._header_found = 0             # <<<<<<<<<<<<<<
 
1246
 *         # keys are tuples
 
1247
 * 
 
1248
 */
 
1249
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_header_found = 0;
 
1250
 
 
1251
  __pyx_r = 0;
 
1252
  goto __pyx_L0;
 
1253
  __pyx_L1_error:;
 
1254
  __Pyx_XDECREF(__pyx_t_2);
 
1255
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.__init__");
 
1256
  __pyx_r = -1;
 
1257
  __pyx_L0:;
 
1258
  __Pyx_RefNannyFinishContext();
 
1259
  return __pyx_r;
 
1260
}
 
1261
 
 
1262
/* "bzrlib/_btree_serializer_pyx.pyx":163
 
1263
 *         # keys are tuples
 
1264
 * 
 
1265
 *     cdef extract_key(self, char * last):             # <<<<<<<<<<<<<<
 
1266
 *         """Extract a key.
 
1267
 * 
 
1268
 */
 
1269
 
 
1270
static  PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_extract_key(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_v_self, char *__pyx_v_last) {
 
1271
  char *__pyx_v_temp_ptr;
 
1272
  int __pyx_v_loop_counter;
 
1273
  StaticTuple *__pyx_v_key;
 
1274
  PyObject *__pyx_v_failure_string;
 
1275
  PyObject *__pyx_v_key_element;
 
1276
  PyObject *__pyx_r = NULL;
 
1277
  PyObject *__pyx_t_1 = NULL;
 
1278
  int __pyx_t_2;
 
1279
  int __pyx_t_3;
 
1280
  PyObject *__pyx_t_4 = NULL;
 
1281
  int __pyx_t_5;
 
1282
  int __pyx_t_6;
 
1283
  int __pyx_t_7;
 
1284
  __Pyx_RefNannySetupContext("extract_key");
 
1285
  __pyx_v_key = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
1286
  __pyx_v_failure_string = Py_None; __Pyx_INCREF(Py_None);
 
1287
  __pyx_v_key_element = Py_None; __Pyx_INCREF(Py_None);
 
1288
 
 
1289
  /* "bzrlib/_btree_serializer_pyx.pyx":173
 
1290
 *         cdef StaticTuple key
 
1291
 * 
 
1292
 *         key = StaticTuple_New(self.key_length)             # <<<<<<<<<<<<<<
 
1293
 *         for loop_counter from 0 <= loop_counter < self.key_length:
 
1294
 *             # grab a key segment
 
1295
 */
 
1296
  __pyx_t_1 = ((PyObject *)StaticTuple_New(__pyx_v_self->key_length)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1297
  __Pyx_GOTREF(__pyx_t_1);
 
1298
  __Pyx_DECREF(((PyObject *)__pyx_v_key));
 
1299
  __pyx_v_key = ((StaticTuple *)__pyx_t_1);
 
1300
  __pyx_t_1 = 0;
 
1301
 
 
1302
  /* "bzrlib/_btree_serializer_pyx.pyx":174
 
1303
 * 
 
1304
 *         key = StaticTuple_New(self.key_length)
 
1305
 *         for loop_counter from 0 <= loop_counter < self.key_length:             # <<<<<<<<<<<<<<
 
1306
 *             # grab a key segment
 
1307
 *             temp_ptr = <char*>memchr(self._start, c'\0', last - self._start)
 
1308
 */
 
1309
  __pyx_t_2 = __pyx_v_self->key_length;
 
1310
  for (__pyx_v_loop_counter = 0; __pyx_v_loop_counter < __pyx_t_2; __pyx_v_loop_counter++) {
 
1311
 
 
1312
    /* "bzrlib/_btree_serializer_pyx.pyx":176
 
1313
 *         for loop_counter from 0 <= loop_counter < self.key_length:
 
1314
 *             # grab a key segment
 
1315
 *             temp_ptr = <char*>memchr(self._start, c'\0', last - self._start)             # <<<<<<<<<<<<<<
 
1316
 *             if temp_ptr == NULL:
 
1317
 *                 if loop_counter + 1 == self.key_length:
 
1318
 */
 
1319
    __pyx_v_temp_ptr = ((char *)memchr(__pyx_v_self->_start, '\x00', (__pyx_v_last - __pyx_v_self->_start)));
 
1320
 
 
1321
    /* "bzrlib/_btree_serializer_pyx.pyx":177
 
1322
 *             # grab a key segment
 
1323
 *             temp_ptr = <char*>memchr(self._start, c'\0', last - self._start)
 
1324
 *             if temp_ptr == NULL:             # <<<<<<<<<<<<<<
 
1325
 *                 if loop_counter + 1 == self.key_length:
 
1326
 *                     # capture to last
 
1327
 */
 
1328
    __pyx_t_3 = (__pyx_v_temp_ptr == NULL);
 
1329
    if (__pyx_t_3) {
 
1330
 
 
1331
      /* "bzrlib/_btree_serializer_pyx.pyx":178
 
1332
 *             temp_ptr = <char*>memchr(self._start, c'\0', last - self._start)
 
1333
 *             if temp_ptr == NULL:
 
1334
 *                 if loop_counter + 1 == self.key_length:             # <<<<<<<<<<<<<<
 
1335
 *                     # capture to last
 
1336
 *                     temp_ptr = last
 
1337
 */
 
1338
      __pyx_t_3 = ((__pyx_v_loop_counter + 1) == __pyx_v_self->key_length);
 
1339
      if (__pyx_t_3) {
 
1340
 
 
1341
        /* "bzrlib/_btree_serializer_pyx.pyx":180
 
1342
 *                 if loop_counter + 1 == self.key_length:
 
1343
 *                     # capture to last
 
1344
 *                     temp_ptr = last             # <<<<<<<<<<<<<<
 
1345
 *                 else:
 
1346
 *                     # Invalid line
 
1347
 */
 
1348
        __pyx_v_temp_ptr = __pyx_v_last;
 
1349
        goto __pyx_L6;
 
1350
      }
 
1351
      /*else*/ {
 
1352
 
 
1353
        /* "bzrlib/_btree_serializer_pyx.pyx":185
 
1354
 *                     failure_string = ("invalid key, wanted segment from " +
 
1355
 *                         repr(safe_string_from_size(self._start,
 
1356
 *                                                    last - self._start)))             # <<<<<<<<<<<<<<
 
1357
 *                     raise AssertionError(failure_string)
 
1358
 *             # capture the key string
 
1359
 */
 
1360
        __pyx_t_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_self->_start, (__pyx_v_last - __pyx_v_self->_start)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1361
        __Pyx_GOTREF(__pyx_t_1);
 
1362
        __pyx_t_4 = PyObject_Repr(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1363
        __Pyx_GOTREF(__pyx_t_4);
 
1364
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
1365
        __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_kp_s_2), __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1366
        __Pyx_GOTREF(__pyx_t_1);
 
1367
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
1368
        __Pyx_DECREF(__pyx_v_failure_string);
 
1369
        __pyx_v_failure_string = __pyx_t_1;
 
1370
        __pyx_t_1 = 0;
 
1371
 
 
1372
        /* "bzrlib/_btree_serializer_pyx.pyx":186
 
1373
 *                         repr(safe_string_from_size(self._start,
 
1374
 *                                                    last - self._start)))
 
1375
 *                     raise AssertionError(failure_string)             # <<<<<<<<<<<<<<
 
1376
 *             # capture the key string
 
1377
 *             if (self.key_length == 1
 
1378
 */
 
1379
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1380
        __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
1381
        __Pyx_INCREF(__pyx_v_failure_string);
 
1382
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_failure_string);
 
1383
        __Pyx_GIVEREF(__pyx_v_failure_string);
 
1384
        __pyx_t_4 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1385
        __Pyx_GOTREF(__pyx_t_4);
 
1386
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
1387
        __Pyx_Raise(__pyx_t_4, 0, 0);
 
1388
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
1389
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1390
      }
 
1391
      __pyx_L6:;
 
1392
      goto __pyx_L5;
 
1393
    }
 
1394
    __pyx_L5:;
 
1395
 
 
1396
    /* "bzrlib/_btree_serializer_pyx.pyx":188
 
1397
 *                     raise AssertionError(failure_string)
 
1398
 *             # capture the key string
 
1399
 *             if (self.key_length == 1             # <<<<<<<<<<<<<<
 
1400
 *                 and (temp_ptr - self._start) == 45
 
1401
 *                 and strncmp(self._start, 'sha1:', 5) == 0):
 
1402
 */
 
1403
    __pyx_t_3 = (__pyx_v_self->key_length == 1);
 
1404
    if (__pyx_t_3) {
 
1405
 
 
1406
      /* "bzrlib/_btree_serializer_pyx.pyx":189
 
1407
 *             # capture the key string
 
1408
 *             if (self.key_length == 1
 
1409
 *                 and (temp_ptr - self._start) == 45             # <<<<<<<<<<<<<<
 
1410
 *                 and strncmp(self._start, 'sha1:', 5) == 0):
 
1411
 *                 key_element = safe_string_from_size(self._start,
 
1412
 */
 
1413
      __pyx_t_5 = ((__pyx_v_temp_ptr - __pyx_v_self->_start) == 45);
 
1414
      if (__pyx_t_5) {
 
1415
 
 
1416
        /* "bzrlib/_btree_serializer_pyx.pyx":190
 
1417
 *             if (self.key_length == 1
 
1418
 *                 and (temp_ptr - self._start) == 45
 
1419
 *                 and strncmp(self._start, 'sha1:', 5) == 0):             # <<<<<<<<<<<<<<
 
1420
 *                 key_element = safe_string_from_size(self._start,
 
1421
 *                                                     temp_ptr - self._start)
 
1422
 */
 
1423
        __pyx_t_6 = (strncmp(__pyx_v_self->_start, __pyx_k_3, 5) == 0);
 
1424
        __pyx_t_7 = __pyx_t_6;
 
1425
      } else {
 
1426
        __pyx_t_7 = __pyx_t_5;
 
1427
      }
 
1428
      __pyx_t_5 = __pyx_t_7;
 
1429
    } else {
 
1430
      __pyx_t_5 = __pyx_t_3;
 
1431
    }
 
1432
    if (__pyx_t_5) {
 
1433
 
 
1434
      /* "bzrlib/_btree_serializer_pyx.pyx":192
 
1435
 *                 and strncmp(self._start, 'sha1:', 5) == 0):
 
1436
 *                 key_element = safe_string_from_size(self._start,
 
1437
 *                                                     temp_ptr - self._start)             # <<<<<<<<<<<<<<
 
1438
 *             else:
 
1439
 *                 key_element = safe_interned_string_from_size(self._start,
 
1440
 */
 
1441
      __pyx_t_4 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_self->_start, (__pyx_v_temp_ptr - __pyx_v_self->_start)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1442
      __Pyx_GOTREF(__pyx_t_4);
 
1443
      __Pyx_DECREF(__pyx_v_key_element);
 
1444
      __pyx_v_key_element = __pyx_t_4;
 
1445
      __pyx_t_4 = 0;
 
1446
      goto __pyx_L7;
 
1447
    }
 
1448
    /*else*/ {
 
1449
 
 
1450
      /* "bzrlib/_btree_serializer_pyx.pyx":195
 
1451
 *             else:
 
1452
 *                 key_element = safe_interned_string_from_size(self._start,
 
1453
 *                                                          temp_ptr - self._start)             # <<<<<<<<<<<<<<
 
1454
 *             # advance our pointer
 
1455
 *             self._start = temp_ptr + 1
 
1456
 */
 
1457
      __pyx_t_4 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size(__pyx_v_self->_start, (__pyx_v_temp_ptr - __pyx_v_self->_start)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1458
      __Pyx_GOTREF(__pyx_t_4);
 
1459
      __Pyx_DECREF(__pyx_v_key_element);
 
1460
      __pyx_v_key_element = __pyx_t_4;
 
1461
      __pyx_t_4 = 0;
 
1462
    }
 
1463
    __pyx_L7:;
 
1464
 
 
1465
    /* "bzrlib/_btree_serializer_pyx.pyx":197
 
1466
 *                                                          temp_ptr - self._start)
 
1467
 *             # advance our pointer
 
1468
 *             self._start = temp_ptr + 1             # <<<<<<<<<<<<<<
 
1469
 *             Py_INCREF(key_element)
 
1470
 *             StaticTuple_SET_ITEM(key, loop_counter, key_element)
 
1471
 */
 
1472
    __pyx_v_self->_start = (__pyx_v_temp_ptr + 1);
 
1473
 
 
1474
    /* "bzrlib/_btree_serializer_pyx.pyx":198
 
1475
 *             # advance our pointer
 
1476
 *             self._start = temp_ptr + 1
 
1477
 *             Py_INCREF(key_element)             # <<<<<<<<<<<<<<
 
1478
 *             StaticTuple_SET_ITEM(key, loop_counter, key_element)
 
1479
 *         key = StaticTuple_Intern(key)
 
1480
 */
 
1481
    Py_INCREF(__pyx_v_key_element);
 
1482
 
 
1483
    /* "bzrlib/_btree_serializer_pyx.pyx":199
 
1484
 *             self._start = temp_ptr + 1
 
1485
 *             Py_INCREF(key_element)
 
1486
 *             StaticTuple_SET_ITEM(key, loop_counter, key_element)             # <<<<<<<<<<<<<<
 
1487
 *         key = StaticTuple_Intern(key)
 
1488
 *         return key
 
1489
 */
 
1490
    StaticTuple_SET_ITEM(__pyx_v_key, __pyx_v_loop_counter, __pyx_v_key_element);
 
1491
  }
 
1492
 
 
1493
  /* "bzrlib/_btree_serializer_pyx.pyx":200
 
1494
 *             Py_INCREF(key_element)
 
1495
 *             StaticTuple_SET_ITEM(key, loop_counter, key_element)
 
1496
 *         key = StaticTuple_Intern(key)             # <<<<<<<<<<<<<<
 
1497
 *         return key
 
1498
 * 
 
1499
 */
 
1500
  __pyx_t_4 = ((PyObject *)StaticTuple_Intern(__pyx_v_key)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1501
  __Pyx_GOTREF(__pyx_t_4);
 
1502
  __Pyx_DECREF(((PyObject *)__pyx_v_key));
 
1503
  __pyx_v_key = ((StaticTuple *)__pyx_t_4);
 
1504
  __pyx_t_4 = 0;
 
1505
 
 
1506
  /* "bzrlib/_btree_serializer_pyx.pyx":201
 
1507
 *             StaticTuple_SET_ITEM(key, loop_counter, key_element)
 
1508
 *         key = StaticTuple_Intern(key)
 
1509
 *         return key             # <<<<<<<<<<<<<<
 
1510
 * 
 
1511
 *     cdef int process_line(self) except -1:
 
1512
 */
 
1513
  __Pyx_XDECREF(__pyx_r);
 
1514
  __Pyx_INCREF(((PyObject *)__pyx_v_key));
 
1515
  __pyx_r = ((PyObject *)__pyx_v_key);
 
1516
  goto __pyx_L0;
 
1517
 
 
1518
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
1519
  goto __pyx_L0;
 
1520
  __pyx_L1_error:;
 
1521
  __Pyx_XDECREF(__pyx_t_1);
 
1522
  __Pyx_XDECREF(__pyx_t_4);
 
1523
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.extract_key");
 
1524
  __pyx_r = 0;
 
1525
  __pyx_L0:;
 
1526
  __Pyx_DECREF((PyObject *)__pyx_v_key);
 
1527
  __Pyx_DECREF(__pyx_v_failure_string);
 
1528
  __Pyx_DECREF(__pyx_v_key_element);
 
1529
  __Pyx_XGIVEREF(__pyx_r);
 
1530
  __Pyx_RefNannyFinishContext();
 
1531
  return __pyx_r;
 
1532
}
 
1533
 
 
1534
/* "bzrlib/_btree_serializer_pyx.pyx":203
 
1535
 *         return key
 
1536
 * 
 
1537
 *     cdef int process_line(self) except -1:             # <<<<<<<<<<<<<<
 
1538
 *         """Process a line in the bytes."""
 
1539
 *         cdef char *last
 
1540
 */
 
1541
 
 
1542
static  int __pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_process_line(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_v_self) {
 
1543
  char *__pyx_v_last;
 
1544
  char *__pyx_v_temp_ptr;
 
1545
  char *__pyx_v_ref_ptr;
 
1546
  char *__pyx_v_next_start;
 
1547
  int __pyx_v_loop_counter;
 
1548
  Py_ssize_t __pyx_v_str_len;
 
1549
  PyObject *__pyx_v_key;
 
1550
  PyObject *__pyx_v_value;
 
1551
  StaticTuple *__pyx_v_ref_lists;
 
1552
  PyObject *__pyx_v_ref_list;
 
1553
  StaticTuple *__pyx_v_node_value;
 
1554
  int __pyx_r;
 
1555
  int __pyx_t_1;
 
1556
  PyObject *__pyx_t_2 = NULL;
 
1557
  PyObject *__pyx_t_3 = NULL;
 
1558
  int __pyx_t_4;
 
1559
  int __pyx_t_5;
 
1560
  int __pyx_t_6;
 
1561
  PyObject *__pyx_t_7 = NULL;
 
1562
  __Pyx_RefNannySetupContext("process_line");
 
1563
  __pyx_v_key = Py_None; __Pyx_INCREF(Py_None);
 
1564
  __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);
 
1565
  __pyx_v_ref_lists = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
1566
  __pyx_v_ref_list = Py_None; __Pyx_INCREF(Py_None);
 
1567
  __pyx_v_node_value = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
1568
 
 
1569
  /* "bzrlib/_btree_serializer_pyx.pyx":212
 
1570
 *         cdef Py_ssize_t str_len
 
1571
 * 
 
1572
 *         self._start = self._cur_str             # <<<<<<<<<<<<<<
 
1573
 *         # Find the next newline
 
1574
 *         last = <char*>memchr(self._start, c'\n', self._end_str - self._start)
 
1575
 */
 
1576
  __pyx_v_self->_start = __pyx_v_self->_cur_str;
 
1577
 
 
1578
  /* "bzrlib/_btree_serializer_pyx.pyx":214
 
1579
 *         self._start = self._cur_str
 
1580
 *         # Find the next newline
 
1581
 *         last = <char*>memchr(self._start, c'\n', self._end_str - self._start)             # <<<<<<<<<<<<<<
 
1582
 *         if last == NULL:
 
1583
 *             # Process until the end of the file
 
1584
 */
 
1585
  __pyx_v_last = ((char *)memchr(__pyx_v_self->_start, '\n', (__pyx_v_self->_end_str - __pyx_v_self->_start)));
 
1586
 
 
1587
  /* "bzrlib/_btree_serializer_pyx.pyx":215
 
1588
 *         # Find the next newline
 
1589
 *         last = <char*>memchr(self._start, c'\n', self._end_str - self._start)
 
1590
 *         if last == NULL:             # <<<<<<<<<<<<<<
 
1591
 *             # Process until the end of the file
 
1592
 *             last = self._end_str
 
1593
 */
 
1594
  __pyx_t_1 = (__pyx_v_last == NULL);
 
1595
  if (__pyx_t_1) {
 
1596
 
 
1597
    /* "bzrlib/_btree_serializer_pyx.pyx":217
 
1598
 *         if last == NULL:
 
1599
 *             # Process until the end of the file
 
1600
 *             last = self._end_str             # <<<<<<<<<<<<<<
 
1601
 *             self._cur_str = self._end_str
 
1602
 *         else:
 
1603
 */
 
1604
    __pyx_v_last = __pyx_v_self->_end_str;
 
1605
 
 
1606
    /* "bzrlib/_btree_serializer_pyx.pyx":218
 
1607
 *             # Process until the end of the file
 
1608
 *             last = self._end_str
 
1609
 *             self._cur_str = self._end_str             # <<<<<<<<<<<<<<
 
1610
 *         else:
 
1611
 *             # And the next string is right after it
 
1612
 */
 
1613
    __pyx_v_self->_cur_str = __pyx_v_self->_end_str;
 
1614
    goto __pyx_L3;
 
1615
  }
 
1616
  /*else*/ {
 
1617
 
 
1618
    /* "bzrlib/_btree_serializer_pyx.pyx":221
 
1619
 *         else:
 
1620
 *             # And the next string is right after it
 
1621
 *             self._cur_str = last + 1             # <<<<<<<<<<<<<<
 
1622
 *             # The last character is right before the '\n'
 
1623
 * 
 
1624
 */
 
1625
    __pyx_v_self->_cur_str = (__pyx_v_last + 1);
 
1626
  }
 
1627
  __pyx_L3:;
 
1628
 
 
1629
  /* "bzrlib/_btree_serializer_pyx.pyx":224
 
1630
 *             # The last character is right before the '\n'
 
1631
 * 
 
1632
 *         if last == self._start:             # <<<<<<<<<<<<<<
 
1633
 *             # parsed it all.
 
1634
 *             return 0
 
1635
 */
 
1636
  __pyx_t_1 = (__pyx_v_last == __pyx_v_self->_start);
 
1637
  if (__pyx_t_1) {
 
1638
 
 
1639
    /* "bzrlib/_btree_serializer_pyx.pyx":226
 
1640
 *         if last == self._start:
 
1641
 *             # parsed it all.
 
1642
 *             return 0             # <<<<<<<<<<<<<<
 
1643
 *         if last < self._start:
 
1644
 *             # Unexpected error condition - fail
 
1645
 */
 
1646
    __pyx_r = 0;
 
1647
    goto __pyx_L0;
 
1648
    goto __pyx_L4;
 
1649
  }
 
1650
  __pyx_L4:;
 
1651
 
 
1652
  /* "bzrlib/_btree_serializer_pyx.pyx":227
 
1653
 *             # parsed it all.
 
1654
 *             return 0
 
1655
 *         if last < self._start:             # <<<<<<<<<<<<<<
 
1656
 *             # Unexpected error condition - fail
 
1657
 *             raise AssertionError("last < self._start")
 
1658
 */
 
1659
  __pyx_t_1 = (__pyx_v_last < __pyx_v_self->_start);
 
1660
  if (__pyx_t_1) {
 
1661
 
 
1662
    /* "bzrlib/_btree_serializer_pyx.pyx":229
 
1663
 *         if last < self._start:
 
1664
 *             # Unexpected error condition - fail
 
1665
 *             raise AssertionError("last < self._start")             # <<<<<<<<<<<<<<
 
1666
 *         if 0 == self._header_found:
 
1667
 *             # The first line in a leaf node is the header "type=leaf\n"
 
1668
 */
 
1669
    __pyx_t_2 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1670
    __Pyx_GOTREF(__pyx_t_2);
 
1671
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
1672
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
1673
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1674
    goto __pyx_L5;
 
1675
  }
 
1676
  __pyx_L5:;
 
1677
 
 
1678
  /* "bzrlib/_btree_serializer_pyx.pyx":230
 
1679
 *             # Unexpected error condition - fail
 
1680
 *             raise AssertionError("last < self._start")
 
1681
 *         if 0 == self._header_found:             # <<<<<<<<<<<<<<
 
1682
 *             # The first line in a leaf node is the header "type=leaf\n"
 
1683
 *             if strncmp("type=leaf", self._start, last - self._start) == 0:
 
1684
 */
 
1685
  __pyx_t_1 = (0 == __pyx_v_self->_header_found);
 
1686
  if (__pyx_t_1) {
 
1687
 
 
1688
    /* "bzrlib/_btree_serializer_pyx.pyx":232
 
1689
 *         if 0 == self._header_found:
 
1690
 *             # The first line in a leaf node is the header "type=leaf\n"
 
1691
 *             if strncmp("type=leaf", self._start, last - self._start) == 0:             # <<<<<<<<<<<<<<
 
1692
 *                 self._header_found = 1
 
1693
 *                 return 0
 
1694
 */
 
1695
    __pyx_t_1 = (strncmp(__pyx_k_6, __pyx_v_self->_start, (__pyx_v_last - __pyx_v_self->_start)) == 0);
 
1696
    if (__pyx_t_1) {
 
1697
 
 
1698
      /* "bzrlib/_btree_serializer_pyx.pyx":233
 
1699
 *             # The first line in a leaf node is the header "type=leaf\n"
 
1700
 *             if strncmp("type=leaf", self._start, last - self._start) == 0:
 
1701
 *                 self._header_found = 1             # <<<<<<<<<<<<<<
 
1702
 *                 return 0
 
1703
 *             else:
 
1704
 */
 
1705
      __pyx_v_self->_header_found = 1;
 
1706
 
 
1707
      /* "bzrlib/_btree_serializer_pyx.pyx":234
 
1708
 *             if strncmp("type=leaf", self._start, last - self._start) == 0:
 
1709
 *                 self._header_found = 1
 
1710
 *                 return 0             # <<<<<<<<<<<<<<
 
1711
 *             else:
 
1712
 *                 raise AssertionError('Node did not start with "type=leaf": %r'
 
1713
 */
 
1714
      __pyx_r = 0;
 
1715
      goto __pyx_L0;
 
1716
      goto __pyx_L7;
 
1717
    }
 
1718
    /*else*/ {
 
1719
 
 
1720
      /* "bzrlib/_btree_serializer_pyx.pyx":237
 
1721
 *             else:
 
1722
 *                 raise AssertionError('Node did not start with "type=leaf": %r'
 
1723
 *                     % (safe_string_from_size(self._start, last - self._start)))             # <<<<<<<<<<<<<<
 
1724
 * 
 
1725
 *         key = self.extract_key(last)
 
1726
 */
 
1727
      __pyx_t_2 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_self->_start, (__pyx_v_last - __pyx_v_self->_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1728
      __Pyx_GOTREF(__pyx_t_2);
 
1729
      __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1730
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
1731
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
1732
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1733
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
 
1734
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
 
1735
      __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
 
1736
      __pyx_t_3 = 0;
 
1737
      __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1738
      __Pyx_GOTREF(__pyx_t_3);
 
1739
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
 
1740
      __Pyx_Raise(__pyx_t_3, 0, 0);
 
1741
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
1742
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1743
    }
 
1744
    __pyx_L7:;
 
1745
    goto __pyx_L6;
 
1746
  }
 
1747
  __pyx_L6:;
 
1748
 
 
1749
  /* "bzrlib/_btree_serializer_pyx.pyx":239
 
1750
 *                     % (safe_string_from_size(self._start, last - self._start)))
 
1751
 * 
 
1752
 *         key = self.extract_key(last)             # <<<<<<<<<<<<<<
 
1753
 *         # find the value area
 
1754
 *         temp_ptr = <char*>_my_memrchr(self._start, c'\0', last - self._start)
 
1755
 */
 
1756
  __pyx_t_3 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self->__pyx_vtab)->extract_key(__pyx_v_self, __pyx_v_last); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1757
  __Pyx_GOTREF(__pyx_t_3);
 
1758
  __Pyx_DECREF(__pyx_v_key);
 
1759
  __pyx_v_key = __pyx_t_3;
 
1760
  __pyx_t_3 = 0;
 
1761
 
 
1762
  /* "bzrlib/_btree_serializer_pyx.pyx":241
 
1763
 *         key = self.extract_key(last)
 
1764
 *         # find the value area
 
1765
 *         temp_ptr = <char*>_my_memrchr(self._start, c'\0', last - self._start)             # <<<<<<<<<<<<<<
 
1766
 *         if temp_ptr == NULL:
 
1767
 *             # Invalid line
 
1768
 */
 
1769
  __pyx_v_temp_ptr = ((char *)__pyx_f_6bzrlib_21_btree_serializer_pyx__my_memrchr(__pyx_v_self->_start, '\x00', (__pyx_v_last - __pyx_v_self->_start)));
 
1770
 
 
1771
  /* "bzrlib/_btree_serializer_pyx.pyx":242
 
1772
 *         # find the value area
 
1773
 *         temp_ptr = <char*>_my_memrchr(self._start, c'\0', last - self._start)
 
1774
 *         if temp_ptr == NULL:             # <<<<<<<<<<<<<<
 
1775
 *             # Invalid line
 
1776
 *             raise AssertionError("Failed to find the value area")
 
1777
 */
 
1778
  __pyx_t_1 = (__pyx_v_temp_ptr == NULL);
 
1779
  if (__pyx_t_1) {
 
1780
 
 
1781
    /* "bzrlib/_btree_serializer_pyx.pyx":244
 
1782
 *         if temp_ptr == NULL:
 
1783
 *             # Invalid line
 
1784
 *             raise AssertionError("Failed to find the value area")             # <<<<<<<<<<<<<<
 
1785
 *         else:
 
1786
 *             # Because of how conversions were done, we ended up with *lots* of
 
1787
 */
 
1788
    __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1789
    __Pyx_GOTREF(__pyx_t_3);
 
1790
    __Pyx_Raise(__pyx_t_3, 0, 0);
 
1791
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
1792
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1793
    goto __pyx_L8;
 
1794
  }
 
1795
  /*else*/ {
 
1796
 
 
1797
    /* "bzrlib/_btree_serializer_pyx.pyx":252
 
1798
 *             # something like '12607215 328306 0 0', which ends up consuming 1MB
 
1799
 *             # of memory, just for those strings.
 
1800
 *             str_len = last - temp_ptr - 1             # <<<<<<<<<<<<<<
 
1801
 *             if (str_len > 4
 
1802
 *                 and strncmp(" 0 0", last - 4, 4) == 0):
 
1803
 */
 
1804
    __pyx_v_str_len = ((__pyx_v_last - __pyx_v_temp_ptr) - 1);
 
1805
 
 
1806
    /* "bzrlib/_btree_serializer_pyx.pyx":253
 
1807
 *             # of memory, just for those strings.
 
1808
 *             str_len = last - temp_ptr - 1
 
1809
 *             if (str_len > 4             # <<<<<<<<<<<<<<
 
1810
 *                 and strncmp(" 0 0", last - 4, 4) == 0):
 
1811
 *                 # This drops peak mem for bzr.dev from 87.4MB => 86.2MB
 
1812
 */
 
1813
    __pyx_t_1 = (__pyx_v_str_len > 4);
 
1814
    if (__pyx_t_1) {
 
1815
 
 
1816
      /* "bzrlib/_btree_serializer_pyx.pyx":254
 
1817
 *             str_len = last - temp_ptr - 1
 
1818
 *             if (str_len > 4
 
1819
 *                 and strncmp(" 0 0", last - 4, 4) == 0):             # <<<<<<<<<<<<<<
 
1820
 *                 # This drops peak mem for bzr.dev from 87.4MB => 86.2MB
 
1821
 *                 # For Launchpad 236MB => 232MB
 
1822
 */
 
1823
      __pyx_t_4 = (strncmp(__pyx_k_10, (__pyx_v_last - 4), 4) == 0);
 
1824
      __pyx_t_5 = __pyx_t_4;
 
1825
    } else {
 
1826
      __pyx_t_5 = __pyx_t_1;
 
1827
    }
 
1828
    if (__pyx_t_5) {
 
1829
 
 
1830
      /* "bzrlib/_btree_serializer_pyx.pyx":257
 
1831
 *                 # This drops peak mem for bzr.dev from 87.4MB => 86.2MB
 
1832
 *                 # For Launchpad 236MB => 232MB
 
1833
 *                 value = safe_interned_string_from_size(temp_ptr + 1, str_len)             # <<<<<<<<<<<<<<
 
1834
 *             else:
 
1835
 *                 value = safe_string_from_size(temp_ptr + 1, str_len)
 
1836
 */
 
1837
      __pyx_t_3 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size((__pyx_v_temp_ptr + 1), __pyx_v_str_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1838
      __Pyx_GOTREF(__pyx_t_3);
 
1839
      __Pyx_DECREF(__pyx_v_value);
 
1840
      __pyx_v_value = __pyx_t_3;
 
1841
      __pyx_t_3 = 0;
 
1842
      goto __pyx_L9;
 
1843
    }
 
1844
    /*else*/ {
 
1845
 
 
1846
      /* "bzrlib/_btree_serializer_pyx.pyx":259
 
1847
 *                 value = safe_interned_string_from_size(temp_ptr + 1, str_len)
 
1848
 *             else:
 
1849
 *                 value = safe_string_from_size(temp_ptr + 1, str_len)             # <<<<<<<<<<<<<<
 
1850
 *             # shrink the references end point
 
1851
 *             last = temp_ptr
 
1852
 */
 
1853
      __pyx_t_3 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size((__pyx_v_temp_ptr + 1), __pyx_v_str_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1854
      __Pyx_GOTREF(__pyx_t_3);
 
1855
      __Pyx_DECREF(__pyx_v_value);
 
1856
      __pyx_v_value = __pyx_t_3;
 
1857
      __pyx_t_3 = 0;
 
1858
    }
 
1859
    __pyx_L9:;
 
1860
 
 
1861
    /* "bzrlib/_btree_serializer_pyx.pyx":261
 
1862
 *                 value = safe_string_from_size(temp_ptr + 1, str_len)
 
1863
 *             # shrink the references end point
 
1864
 *             last = temp_ptr             # <<<<<<<<<<<<<<
 
1865
 * 
 
1866
 *         if self.ref_list_length:
 
1867
 */
 
1868
    __pyx_v_last = __pyx_v_temp_ptr;
 
1869
  }
 
1870
  __pyx_L8:;
 
1871
 
 
1872
  /* "bzrlib/_btree_serializer_pyx.pyx":263
 
1873
 *             last = temp_ptr
 
1874
 * 
 
1875
 *         if self.ref_list_length:             # <<<<<<<<<<<<<<
 
1876
 *             ref_lists = StaticTuple_New(self.ref_list_length)
 
1877
 *             loop_counter = 0
 
1878
 */
 
1879
  if (__pyx_v_self->ref_list_length) {
 
1880
 
 
1881
    /* "bzrlib/_btree_serializer_pyx.pyx":264
 
1882
 * 
 
1883
 *         if self.ref_list_length:
 
1884
 *             ref_lists = StaticTuple_New(self.ref_list_length)             # <<<<<<<<<<<<<<
 
1885
 *             loop_counter = 0
 
1886
 *             while loop_counter < self.ref_list_length:
 
1887
 */
 
1888
    __pyx_t_3 = ((PyObject *)StaticTuple_New(__pyx_v_self->ref_list_length)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1889
    __Pyx_GOTREF(__pyx_t_3);
 
1890
    __Pyx_DECREF(((PyObject *)__pyx_v_ref_lists));
 
1891
    __pyx_v_ref_lists = ((StaticTuple *)__pyx_t_3);
 
1892
    __pyx_t_3 = 0;
 
1893
 
 
1894
    /* "bzrlib/_btree_serializer_pyx.pyx":265
 
1895
 *         if self.ref_list_length:
 
1896
 *             ref_lists = StaticTuple_New(self.ref_list_length)
 
1897
 *             loop_counter = 0             # <<<<<<<<<<<<<<
 
1898
 *             while loop_counter < self.ref_list_length:
 
1899
 *                 ref_list = []
 
1900
 */
 
1901
    __pyx_v_loop_counter = 0;
 
1902
 
 
1903
    /* "bzrlib/_btree_serializer_pyx.pyx":266
 
1904
 *             ref_lists = StaticTuple_New(self.ref_list_length)
 
1905
 *             loop_counter = 0
 
1906
 *             while loop_counter < self.ref_list_length:             # <<<<<<<<<<<<<<
 
1907
 *                 ref_list = []
 
1908
 *                 # extract a reference list
 
1909
 */
 
1910
    while (1) {
 
1911
      __pyx_t_5 = (__pyx_v_loop_counter < __pyx_v_self->ref_list_length);
 
1912
      if (!__pyx_t_5) break;
 
1913
 
 
1914
      /* "bzrlib/_btree_serializer_pyx.pyx":267
 
1915
 *             loop_counter = 0
 
1916
 *             while loop_counter < self.ref_list_length:
 
1917
 *                 ref_list = []             # <<<<<<<<<<<<<<
 
1918
 *                 # extract a reference list
 
1919
 *                 loop_counter = loop_counter + 1
 
1920
 */
 
1921
      __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1922
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
1923
      __Pyx_DECREF(__pyx_v_ref_list);
 
1924
      __pyx_v_ref_list = ((PyObject *)__pyx_t_3);
 
1925
      __pyx_t_3 = 0;
 
1926
 
 
1927
      /* "bzrlib/_btree_serializer_pyx.pyx":269
 
1928
 *                 ref_list = []
 
1929
 *                 # extract a reference list
 
1930
 *                 loop_counter = loop_counter + 1             # <<<<<<<<<<<<<<
 
1931
 *                 if last < self._start:
 
1932
 *                     raise AssertionError("last < self._start")
 
1933
 */
 
1934
      __pyx_v_loop_counter = (__pyx_v_loop_counter + 1);
 
1935
 
 
1936
      /* "bzrlib/_btree_serializer_pyx.pyx":270
 
1937
 *                 # extract a reference list
 
1938
 *                 loop_counter = loop_counter + 1
 
1939
 *                 if last < self._start:             # <<<<<<<<<<<<<<
 
1940
 *                     raise AssertionError("last < self._start")
 
1941
 *                 # find the next reference list end point:
 
1942
 */
 
1943
      __pyx_t_5 = (__pyx_v_last < __pyx_v_self->_start);
 
1944
      if (__pyx_t_5) {
 
1945
 
 
1946
        /* "bzrlib/_btree_serializer_pyx.pyx":271
 
1947
 *                 loop_counter = loop_counter + 1
 
1948
 *                 if last < self._start:
 
1949
 *                     raise AssertionError("last < self._start")             # <<<<<<<<<<<<<<
 
1950
 *                 # find the next reference list end point:
 
1951
 *                 temp_ptr = <char*>memchr(self._start, c'\t', last - self._start)
 
1952
 */
 
1953
        __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1954
        __Pyx_GOTREF(__pyx_t_3);
 
1955
        __Pyx_Raise(__pyx_t_3, 0, 0);
 
1956
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
1957
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1958
        goto __pyx_L13;
 
1959
      }
 
1960
      __pyx_L13:;
 
1961
 
 
1962
      /* "bzrlib/_btree_serializer_pyx.pyx":273
 
1963
 *                     raise AssertionError("last < self._start")
 
1964
 *                 # find the next reference list end point:
 
1965
 *                 temp_ptr = <char*>memchr(self._start, c'\t', last - self._start)             # <<<<<<<<<<<<<<
 
1966
 *                 if temp_ptr == NULL:
 
1967
 *                     # Only valid for the last list
 
1968
 */
 
1969
      __pyx_v_temp_ptr = ((char *)memchr(__pyx_v_self->_start, '\t', (__pyx_v_last - __pyx_v_self->_start)));
 
1970
 
 
1971
      /* "bzrlib/_btree_serializer_pyx.pyx":274
 
1972
 *                 # find the next reference list end point:
 
1973
 *                 temp_ptr = <char*>memchr(self._start, c'\t', last - self._start)
 
1974
 *                 if temp_ptr == NULL:             # <<<<<<<<<<<<<<
 
1975
 *                     # Only valid for the last list
 
1976
 *                     if loop_counter != self.ref_list_length:
 
1977
 */
 
1978
      __pyx_t_5 = (__pyx_v_temp_ptr == NULL);
 
1979
      if (__pyx_t_5) {
 
1980
 
 
1981
        /* "bzrlib/_btree_serializer_pyx.pyx":276
 
1982
 *                 if temp_ptr == NULL:
 
1983
 *                     # Only valid for the last list
 
1984
 *                     if loop_counter != self.ref_list_length:             # <<<<<<<<<<<<<<
 
1985
 *                         # Invalid line
 
1986
 *                         raise AssertionError(
 
1987
 */
 
1988
        __pyx_t_5 = (__pyx_v_loop_counter != __pyx_v_self->ref_list_length);
 
1989
        if (__pyx_t_5) {
 
1990
 
 
1991
          /* "bzrlib/_btree_serializer_pyx.pyx":278
 
1992
 *                     if loop_counter != self.ref_list_length:
 
1993
 *                         # Invalid line
 
1994
 *                         raise AssertionError(             # <<<<<<<<<<<<<<
 
1995
 *                             "invalid key, loop_counter != self.ref_list_length")
 
1996
 *                     else:
 
1997
 */
 
1998
          __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
1999
          __Pyx_GOTREF(__pyx_t_3);
 
2000
          __Pyx_Raise(__pyx_t_3, 0, 0);
 
2001
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
2002
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2003
          goto __pyx_L15;
 
2004
        }
 
2005
        /*else*/ {
 
2006
 
 
2007
          /* "bzrlib/_btree_serializer_pyx.pyx":282
 
2008
 *                     else:
 
2009
 *                         # scan to the end of the ref list area
 
2010
 *                         ref_ptr = last             # <<<<<<<<<<<<<<
 
2011
 *                         next_start = last
 
2012
 *                 else:
 
2013
 */
 
2014
          __pyx_v_ref_ptr = __pyx_v_last;
 
2015
 
 
2016
          /* "bzrlib/_btree_serializer_pyx.pyx":283
 
2017
 *                         # scan to the end of the ref list area
 
2018
 *                         ref_ptr = last
 
2019
 *                         next_start = last             # <<<<<<<<<<<<<<
 
2020
 *                 else:
 
2021
 *                     # scan to the end of this ref list
 
2022
 */
 
2023
          __pyx_v_next_start = __pyx_v_last;
 
2024
        }
 
2025
        __pyx_L15:;
 
2026
        goto __pyx_L14;
 
2027
      }
 
2028
      /*else*/ {
 
2029
 
 
2030
        /* "bzrlib/_btree_serializer_pyx.pyx":286
 
2031
 *                 else:
 
2032
 *                     # scan to the end of this ref list
 
2033
 *                     ref_ptr = temp_ptr             # <<<<<<<<<<<<<<
 
2034
 *                     next_start = temp_ptr + 1
 
2035
 *                 # Now, there may be multiple keys in the ref list.
 
2036
 */
 
2037
        __pyx_v_ref_ptr = __pyx_v_temp_ptr;
 
2038
 
 
2039
        /* "bzrlib/_btree_serializer_pyx.pyx":287
 
2040
 *                     # scan to the end of this ref list
 
2041
 *                     ref_ptr = temp_ptr
 
2042
 *                     next_start = temp_ptr + 1             # <<<<<<<<<<<<<<
 
2043
 *                 # Now, there may be multiple keys in the ref list.
 
2044
 *                 while self._start < ref_ptr:
 
2045
 */
 
2046
        __pyx_v_next_start = (__pyx_v_temp_ptr + 1);
 
2047
      }
 
2048
      __pyx_L14:;
 
2049
 
 
2050
      /* "bzrlib/_btree_serializer_pyx.pyx":289
 
2051
 *                     next_start = temp_ptr + 1
 
2052
 *                 # Now, there may be multiple keys in the ref list.
 
2053
 *                 while self._start < ref_ptr:             # <<<<<<<<<<<<<<
 
2054
 *                     # loop finding keys and extracting them
 
2055
 *                     temp_ptr = <char*>memchr(self._start, c'\r',
 
2056
 */
 
2057
      while (1) {
 
2058
        __pyx_t_5 = (__pyx_v_self->_start < __pyx_v_ref_ptr);
 
2059
        if (!__pyx_t_5) break;
 
2060
 
 
2061
        /* "bzrlib/_btree_serializer_pyx.pyx":292
 
2062
 *                     # loop finding keys and extracting them
 
2063
 *                     temp_ptr = <char*>memchr(self._start, c'\r',
 
2064
 *                                              ref_ptr - self._start)             # <<<<<<<<<<<<<<
 
2065
 *                     if temp_ptr == NULL:
 
2066
 *                         # key runs to the end
 
2067
 */
 
2068
        __pyx_v_temp_ptr = ((char *)memchr(__pyx_v_self->_start, '\r', (__pyx_v_ref_ptr - __pyx_v_self->_start)));
 
2069
 
 
2070
        /* "bzrlib/_btree_serializer_pyx.pyx":293
 
2071
 *                     temp_ptr = <char*>memchr(self._start, c'\r',
 
2072
 *                                              ref_ptr - self._start)
 
2073
 *                     if temp_ptr == NULL:             # <<<<<<<<<<<<<<
 
2074
 *                         # key runs to the end
 
2075
 *                         temp_ptr = ref_ptr
 
2076
 */
 
2077
        __pyx_t_5 = (__pyx_v_temp_ptr == NULL);
 
2078
        if (__pyx_t_5) {
 
2079
 
 
2080
          /* "bzrlib/_btree_serializer_pyx.pyx":295
 
2081
 *                     if temp_ptr == NULL:
 
2082
 *                         # key runs to the end
 
2083
 *                         temp_ptr = ref_ptr             # <<<<<<<<<<<<<<
 
2084
 * 
 
2085
 *                     PyList_Append(ref_list, self.extract_key(temp_ptr))
 
2086
 */
 
2087
          __pyx_v_temp_ptr = __pyx_v_ref_ptr;
 
2088
          goto __pyx_L18;
 
2089
        }
 
2090
        __pyx_L18:;
 
2091
 
 
2092
        /* "bzrlib/_btree_serializer_pyx.pyx":297
 
2093
 *                         temp_ptr = ref_ptr
 
2094
 * 
 
2095
 *                     PyList_Append(ref_list, self.extract_key(temp_ptr))             # <<<<<<<<<<<<<<
 
2096
 *                 ref_list = StaticTuple_Intern(StaticTuple(*ref_list))
 
2097
 *                 Py_INCREF(ref_list)
 
2098
 */
 
2099
        __pyx_t_3 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self->__pyx_vtab)->extract_key(__pyx_v_self, __pyx_v_temp_ptr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2100
        __Pyx_GOTREF(__pyx_t_3);
 
2101
        __pyx_t_6 = PyList_Append(__pyx_v_ref_list, __pyx_t_3); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2102
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
2103
      }
 
2104
 
 
2105
      /* "bzrlib/_btree_serializer_pyx.pyx":298
 
2106
 * 
 
2107
 *                     PyList_Append(ref_list, self.extract_key(temp_ptr))
 
2108
 *                 ref_list = StaticTuple_Intern(StaticTuple(*ref_list))             # <<<<<<<<<<<<<<
 
2109
 *                 Py_INCREF(ref_list)
 
2110
 *                 StaticTuple_SET_ITEM(ref_lists, loop_counter - 1, ref_list)
 
2111
 */
 
2112
      __pyx_t_3 = PySequence_Tuple(__pyx_v_ref_list); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2113
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
2114
      __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2115
      __Pyx_GOTREF(__pyx_t_2);
 
2116
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
2117
      __pyx_t_3 = ((PyObject *)StaticTuple_Intern(((StaticTuple *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2118
      __Pyx_GOTREF(__pyx_t_3);
 
2119
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
2120
      __Pyx_DECREF(__pyx_v_ref_list);
 
2121
      __pyx_v_ref_list = __pyx_t_3;
 
2122
      __pyx_t_3 = 0;
 
2123
 
 
2124
      /* "bzrlib/_btree_serializer_pyx.pyx":299
 
2125
 *                     PyList_Append(ref_list, self.extract_key(temp_ptr))
 
2126
 *                 ref_list = StaticTuple_Intern(StaticTuple(*ref_list))
 
2127
 *                 Py_INCREF(ref_list)             # <<<<<<<<<<<<<<
 
2128
 *                 StaticTuple_SET_ITEM(ref_lists, loop_counter - 1, ref_list)
 
2129
 *                 # prepare for the next reference list
 
2130
 */
 
2131
      Py_INCREF(__pyx_v_ref_list);
 
2132
 
 
2133
      /* "bzrlib/_btree_serializer_pyx.pyx":300
 
2134
 *                 ref_list = StaticTuple_Intern(StaticTuple(*ref_list))
 
2135
 *                 Py_INCREF(ref_list)
 
2136
 *                 StaticTuple_SET_ITEM(ref_lists, loop_counter - 1, ref_list)             # <<<<<<<<<<<<<<
 
2137
 *                 # prepare for the next reference list
 
2138
 *                 self._start = next_start
 
2139
 */
 
2140
      StaticTuple_SET_ITEM(__pyx_v_ref_lists, (__pyx_v_loop_counter - 1), __pyx_v_ref_list);
 
2141
 
 
2142
      /* "bzrlib/_btree_serializer_pyx.pyx":302
 
2143
 *                 StaticTuple_SET_ITEM(ref_lists, loop_counter - 1, ref_list)
 
2144
 *                 # prepare for the next reference list
 
2145
 *                 self._start = next_start             # <<<<<<<<<<<<<<
 
2146
 *             node_value = StaticTuple(value, ref_lists)
 
2147
 *         else:
 
2148
 */
 
2149
      __pyx_v_self->_start = __pyx_v_next_start;
 
2150
    }
 
2151
 
 
2152
    /* "bzrlib/_btree_serializer_pyx.pyx":303
 
2153
 *                 # prepare for the next reference list
 
2154
 *                 self._start = next_start
 
2155
 *             node_value = StaticTuple(value, ref_lists)             # <<<<<<<<<<<<<<
 
2156
 *         else:
 
2157
 *             if last != self._start:
 
2158
 */
 
2159
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2160
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
2161
    __Pyx_INCREF(__pyx_v_value);
 
2162
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_value);
 
2163
    __Pyx_GIVEREF(__pyx_v_value);
 
2164
    __Pyx_INCREF(((PyObject *)__pyx_v_ref_lists));
 
2165
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_ref_lists));
 
2166
    __Pyx_GIVEREF(((PyObject *)__pyx_v_ref_lists));
 
2167
    __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2168
    __Pyx_GOTREF(__pyx_t_2);
 
2169
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
2170
    __Pyx_DECREF(((PyObject *)__pyx_v_node_value));
 
2171
    __pyx_v_node_value = ((StaticTuple *)__pyx_t_2);
 
2172
    __pyx_t_2 = 0;
 
2173
    goto __pyx_L10;
 
2174
  }
 
2175
  /*else*/ {
 
2176
 
 
2177
    /* "bzrlib/_btree_serializer_pyx.pyx":305
 
2178
 *             node_value = StaticTuple(value, ref_lists)
 
2179
 *         else:
 
2180
 *             if last != self._start:             # <<<<<<<<<<<<<<
 
2181
 *                 # unexpected reference data present
 
2182
 *                 raise AssertionError("unexpected reference data present")
 
2183
 */
 
2184
    __pyx_t_5 = (__pyx_v_last != __pyx_v_self->_start);
 
2185
    if (__pyx_t_5) {
 
2186
 
 
2187
      /* "bzrlib/_btree_serializer_pyx.pyx":307
 
2188
 *             if last != self._start:
 
2189
 *                 # unexpected reference data present
 
2190
 *                 raise AssertionError("unexpected reference data present")             # <<<<<<<<<<<<<<
 
2191
 *             node_value = StaticTuple(value, StaticTuple())
 
2192
 *         PyList_Append(self.keys, StaticTuple(key, node_value))
 
2193
 */
 
2194
      __pyx_t_2 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2195
      __Pyx_GOTREF(__pyx_t_2);
 
2196
      __Pyx_Raise(__pyx_t_2, 0, 0);
 
2197
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
2198
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2199
      goto __pyx_L19;
 
2200
    }
 
2201
    __pyx_L19:;
 
2202
 
 
2203
    /* "bzrlib/_btree_serializer_pyx.pyx":308
 
2204
 *                 # unexpected reference data present
 
2205
 *                 raise AssertionError("unexpected reference data present")
 
2206
 *             node_value = StaticTuple(value, StaticTuple())             # <<<<<<<<<<<<<<
 
2207
 *         PyList_Append(self.keys, StaticTuple(key, node_value))
 
2208
 *         return 0
 
2209
 */
 
2210
    __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2211
    __Pyx_GOTREF(__pyx_t_2);
 
2212
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2213
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
2214
    __Pyx_INCREF(__pyx_v_value);
 
2215
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_value);
 
2216
    __Pyx_GIVEREF(__pyx_v_value);
 
2217
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
 
2218
    __Pyx_GIVEREF(__pyx_t_2);
 
2219
    __pyx_t_2 = 0;
 
2220
    __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2221
    __Pyx_GOTREF(__pyx_t_2);
 
2222
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
2223
    __Pyx_DECREF(((PyObject *)__pyx_v_node_value));
 
2224
    __pyx_v_node_value = ((StaticTuple *)__pyx_t_2);
 
2225
    __pyx_t_2 = 0;
 
2226
  }
 
2227
  __pyx_L10:;
 
2228
 
 
2229
  /* "bzrlib/_btree_serializer_pyx.pyx":309
 
2230
 *                 raise AssertionError("unexpected reference data present")
 
2231
 *             node_value = StaticTuple(value, StaticTuple())
 
2232
 *         PyList_Append(self.keys, StaticTuple(key, node_value))             # <<<<<<<<<<<<<<
 
2233
 *         return 0
 
2234
 * 
 
2235
 */
 
2236
  __pyx_t_2 = __pyx_v_self->keys;
 
2237
  __Pyx_INCREF(__pyx_t_2);
 
2238
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2239
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
2240
  __Pyx_INCREF(__pyx_v_key);
 
2241
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key);
 
2242
  __Pyx_GIVEREF(__pyx_v_key);
 
2243
  __Pyx_INCREF(((PyObject *)__pyx_v_node_value));
 
2244
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_node_value));
 
2245
  __Pyx_GIVEREF(((PyObject *)__pyx_v_node_value));
 
2246
  __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2247
  __Pyx_GOTREF(__pyx_t_7);
 
2248
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
2249
  __pyx_t_6 = PyList_Append(__pyx_t_2, __pyx_t_7); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2250
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
2251
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 
2252
 
 
2253
  /* "bzrlib/_btree_serializer_pyx.pyx":310
 
2254
 *             node_value = StaticTuple(value, StaticTuple())
 
2255
 *         PyList_Append(self.keys, StaticTuple(key, node_value))
 
2256
 *         return 0             # <<<<<<<<<<<<<<
 
2257
 * 
 
2258
 *     def parse(self):
 
2259
 */
 
2260
  __pyx_r = 0;
 
2261
  goto __pyx_L0;
 
2262
 
 
2263
  __pyx_r = 0;
 
2264
  goto __pyx_L0;
 
2265
  __pyx_L1_error:;
 
2266
  __Pyx_XDECREF(__pyx_t_2);
 
2267
  __Pyx_XDECREF(__pyx_t_3);
 
2268
  __Pyx_XDECREF(__pyx_t_7);
 
2269
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.process_line");
 
2270
  __pyx_r = -1;
 
2271
  __pyx_L0:;
 
2272
  __Pyx_DECREF(__pyx_v_key);
 
2273
  __Pyx_DECREF(__pyx_v_value);
 
2274
  __Pyx_DECREF((PyObject *)__pyx_v_ref_lists);
 
2275
  __Pyx_DECREF(__pyx_v_ref_list);
 
2276
  __Pyx_DECREF((PyObject *)__pyx_v_node_value);
 
2277
  __Pyx_RefNannyFinishContext();
 
2278
  return __pyx_r;
 
2279
}
 
2280
 
 
2281
/* "bzrlib/_btree_serializer_pyx.pyx":312
 
2282
 *         return 0
 
2283
 * 
 
2284
 *     def parse(self):             # <<<<<<<<<<<<<<
 
2285
 *         cdef Py_ssize_t byte_count
 
2286
 *         if not PyString_CheckExact(self.bytes):
 
2287
 */
 
2288
 
 
2289
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_1parse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
 
2290
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_1parse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
 
2291
  Py_ssize_t __pyx_v_byte_count;
 
2292
  PyObject *__pyx_r = NULL;
 
2293
  PyObject *__pyx_t_1 = NULL;
 
2294
  int __pyx_t_2;
 
2295
  char *__pyx_t_3;
 
2296
  int __pyx_t_4;
 
2297
  __Pyx_RefNannySetupContext("parse");
 
2298
 
 
2299
  /* "bzrlib/_btree_serializer_pyx.pyx":314
 
2300
 *     def parse(self):
 
2301
 *         cdef Py_ssize_t byte_count
 
2302
 *         if not PyString_CheckExact(self.bytes):             # <<<<<<<<<<<<<<
 
2303
 *             raise AssertionError('self.bytes is not a string.')
 
2304
 *         byte_count = PyString_Size(self.bytes)
 
2305
 */
 
2306
  __pyx_t_1 = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes;
 
2307
  __Pyx_INCREF(__pyx_t_1);
 
2308
  __pyx_t_2 = (!PyString_CheckExact(__pyx_t_1));
 
2309
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
2310
  if (__pyx_t_2) {
 
2311
 
 
2312
    /* "bzrlib/_btree_serializer_pyx.pyx":315
 
2313
 *         cdef Py_ssize_t byte_count
 
2314
 *         if not PyString_CheckExact(self.bytes):
 
2315
 *             raise AssertionError('self.bytes is not a string.')             # <<<<<<<<<<<<<<
 
2316
 *         byte_count = PyString_Size(self.bytes)
 
2317
 *         self._cur_str = PyString_AsString(self.bytes)
 
2318
 */
 
2319
    __pyx_t_1 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2320
    __Pyx_GOTREF(__pyx_t_1);
 
2321
    __Pyx_Raise(__pyx_t_1, 0, 0);
 
2322
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
2323
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2324
    goto __pyx_L5;
 
2325
  }
 
2326
  __pyx_L5:;
 
2327
 
 
2328
  /* "bzrlib/_btree_serializer_pyx.pyx":316
 
2329
 *         if not PyString_CheckExact(self.bytes):
 
2330
 *             raise AssertionError('self.bytes is not a string.')
 
2331
 *         byte_count = PyString_Size(self.bytes)             # <<<<<<<<<<<<<<
 
2332
 *         self._cur_str = PyString_AsString(self.bytes)
 
2333
 *         # This points to the last character in the string
 
2334
 */
 
2335
  __pyx_t_1 = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes;
 
2336
  __Pyx_INCREF(__pyx_t_1);
 
2337
  __pyx_v_byte_count = PyString_Size(__pyx_t_1);
 
2338
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
2339
 
 
2340
  /* "bzrlib/_btree_serializer_pyx.pyx":317
 
2341
 *             raise AssertionError('self.bytes is not a string.')
 
2342
 *         byte_count = PyString_Size(self.bytes)
 
2343
 *         self._cur_str = PyString_AsString(self.bytes)             # <<<<<<<<<<<<<<
 
2344
 *         # This points to the last character in the string
 
2345
 *         self._end_str = self._cur_str + byte_count
 
2346
 */
 
2347
  __pyx_t_1 = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes;
 
2348
  __Pyx_INCREF(__pyx_t_1);
 
2349
  __pyx_t_3 = PyString_AsString(__pyx_t_1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2350
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
2351
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str = __pyx_t_3;
 
2352
 
 
2353
  /* "bzrlib/_btree_serializer_pyx.pyx":319
 
2354
 *         self._cur_str = PyString_AsString(self.bytes)
 
2355
 *         # This points to the last character in the string
 
2356
 *         self._end_str = self._cur_str + byte_count             # <<<<<<<<<<<<<<
 
2357
 *         while self._cur_str < self._end_str:
 
2358
 *             self.process_line()
 
2359
 */
 
2360
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_end_str = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str + __pyx_v_byte_count);
 
2361
 
 
2362
  /* "bzrlib/_btree_serializer_pyx.pyx":320
 
2363
 *         # This points to the last character in the string
 
2364
 *         self._end_str = self._cur_str + byte_count
 
2365
 *         while self._cur_str < self._end_str:             # <<<<<<<<<<<<<<
 
2366
 *             self.process_line()
 
2367
 *         return self.keys
 
2368
 */
 
2369
  while (1) {
 
2370
    __pyx_t_2 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str < ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_end_str);
 
2371
    if (!__pyx_t_2) break;
 
2372
 
 
2373
    /* "bzrlib/_btree_serializer_pyx.pyx":321
 
2374
 *         self._end_str = self._cur_str + byte_count
 
2375
 *         while self._cur_str < self._end_str:
 
2376
 *             self.process_line()             # <<<<<<<<<<<<<<
 
2377
 *         return self.keys
 
2378
 * 
 
2379
 */
 
2380
    __pyx_t_4 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->__pyx_vtab)->process_line(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2381
  }
 
2382
 
 
2383
  /* "bzrlib/_btree_serializer_pyx.pyx":322
 
2384
 *         while self._cur_str < self._end_str:
 
2385
 *             self.process_line()
 
2386
 *         return self.keys             # <<<<<<<<<<<<<<
 
2387
 * 
 
2388
 * 
 
2389
 */
 
2390
  __Pyx_XDECREF(__pyx_r);
 
2391
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys);
 
2392
  __pyx_r = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys;
 
2393
  goto __pyx_L0;
 
2394
 
 
2395
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
2396
  goto __pyx_L0;
 
2397
  __pyx_L1_error:;
 
2398
  __Pyx_XDECREF(__pyx_t_1);
 
2399
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.parse");
 
2400
  __pyx_r = NULL;
 
2401
  __pyx_L0:;
 
2402
  __Pyx_XGIVEREF(__pyx_r);
 
2403
  __Pyx_RefNannyFinishContext();
 
2404
  return __pyx_r;
 
2405
}
 
2406
 
 
2407
/* "bzrlib/_btree_serializer_pyx.pyx":325
 
2408
 * 
 
2409
 * 
 
2410
 * def _parse_leaf_lines(bytes, key_length, ref_list_length):             # <<<<<<<<<<<<<<
 
2411
 *     parser = BTreeLeafParser(bytes, key_length, ref_list_length)
 
2412
 *     return parser.parse()
 
2413
 */
 
2414
 
 
2415
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
2416
static PyMethodDef __pyx_mdef_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines = {__Pyx_NAMESTR("_parse_leaf_lines"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
 
2417
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
2418
  PyObject *__pyx_v_bytes = 0;
 
2419
  PyObject *__pyx_v_key_length = 0;
 
2420
  PyObject *__pyx_v_ref_list_length = 0;
 
2421
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_v_parser;
 
2422
  PyObject *__pyx_r = NULL;
 
2423
  PyObject *__pyx_t_1 = NULL;
 
2424
  PyObject *__pyx_t_2 = NULL;
 
2425
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__bytes,&__pyx_n_s__key_length,&__pyx_n_s__ref_list_length,0};
 
2426
  __Pyx_RefNannySetupContext("_parse_leaf_lines");
 
2427
  __pyx_self = __pyx_self;
 
2428
  if (unlikely(__pyx_kwds)) {
 
2429
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
 
2430
    PyObject* values[3] = {0,0,0};
 
2431
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
2432
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
 
2433
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
 
2434
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
 
2435
      case  0: break;
 
2436
      default: goto __pyx_L5_argtuple_error;
 
2437
    }
 
2438
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
2439
      case  0:
 
2440
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bytes);
 
2441
      if (likely(values[0])) kw_args--;
 
2442
      else goto __pyx_L5_argtuple_error;
 
2443
      case  1:
 
2444
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key_length);
 
2445
      if (likely(values[1])) kw_args--;
 
2446
      else {
 
2447
        __Pyx_RaiseArgtupleInvalid("_parse_leaf_lines", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
2448
      }
 
2449
      case  2:
 
2450
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref_list_length);
 
2451
      if (likely(values[2])) kw_args--;
 
2452
      else {
 
2453
        __Pyx_RaiseArgtupleInvalid("_parse_leaf_lines", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
2454
      }
 
2455
    }
 
2456
    if (unlikely(kw_args > 0)) {
 
2457
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_parse_leaf_lines") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
2458
    }
 
2459
    __pyx_v_bytes = values[0];
 
2460
    __pyx_v_key_length = values[1];
 
2461
    __pyx_v_ref_list_length = values[2];
 
2462
  } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
 
2463
    goto __pyx_L5_argtuple_error;
 
2464
  } else {
 
2465
    __pyx_v_bytes = PyTuple_GET_ITEM(__pyx_args, 0);
 
2466
    __pyx_v_key_length = PyTuple_GET_ITEM(__pyx_args, 1);
 
2467
    __pyx_v_ref_list_length = PyTuple_GET_ITEM(__pyx_args, 2);
 
2468
  }
 
2469
  goto __pyx_L4_argument_unpacking_done;
 
2470
  __pyx_L5_argtuple_error:;
 
2471
  __Pyx_RaiseArgtupleInvalid("_parse_leaf_lines", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
2472
  __pyx_L3_error:;
 
2473
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._parse_leaf_lines");
 
2474
  __Pyx_RefNannyFinishContext();
 
2475
  return NULL;
 
2476
  __pyx_L4_argument_unpacking_done:;
 
2477
  __pyx_v_parser = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)Py_None); __Pyx_INCREF(Py_None);
 
2478
 
 
2479
  /* "bzrlib/_btree_serializer_pyx.pyx":326
 
2480
 * 
 
2481
 * def _parse_leaf_lines(bytes, key_length, ref_list_length):
 
2482
 *     parser = BTreeLeafParser(bytes, key_length, ref_list_length)             # <<<<<<<<<<<<<<
 
2483
 *     return parser.parse()
 
2484
 * 
 
2485
 */
 
2486
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2487
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
2488
  __Pyx_INCREF(__pyx_v_bytes);
 
2489
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_bytes);
 
2490
  __Pyx_GIVEREF(__pyx_v_bytes);
 
2491
  __Pyx_INCREF(__pyx_v_key_length);
 
2492
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_key_length);
 
2493
  __Pyx_GIVEREF(__pyx_v_key_length);
 
2494
  __Pyx_INCREF(__pyx_v_ref_list_length);
 
2495
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_ref_list_length);
 
2496
  __Pyx_GIVEREF(__pyx_v_ref_list_length);
 
2497
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2498
  __Pyx_GOTREF(__pyx_t_2);
 
2499
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
2500
  __Pyx_DECREF(((PyObject *)__pyx_v_parser));
 
2501
  __pyx_v_parser = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_t_2);
 
2502
  __pyx_t_2 = 0;
 
2503
 
 
2504
  /* "bzrlib/_btree_serializer_pyx.pyx":327
 
2505
 * def _parse_leaf_lines(bytes, key_length, ref_list_length):
 
2506
 *     parser = BTreeLeafParser(bytes, key_length, ref_list_length)
 
2507
 *     return parser.parse()             # <<<<<<<<<<<<<<
 
2508
 * 
 
2509
 * 
 
2510
 */
 
2511
  __Pyx_XDECREF(__pyx_r);
 
2512
  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_parser), __pyx_n_s__parse); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2513
  __Pyx_GOTREF(__pyx_t_2);
 
2514
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2515
  __Pyx_GOTREF(__pyx_t_1);
 
2516
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
2517
  __pyx_r = __pyx_t_1;
 
2518
  __pyx_t_1 = 0;
 
2519
  goto __pyx_L0;
 
2520
 
 
2521
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
2522
  goto __pyx_L0;
 
2523
  __pyx_L1_error:;
 
2524
  __Pyx_XDECREF(__pyx_t_1);
 
2525
  __Pyx_XDECREF(__pyx_t_2);
 
2526
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._parse_leaf_lines");
 
2527
  __pyx_r = NULL;
 
2528
  __pyx_L0:;
 
2529
  __Pyx_DECREF((PyObject *)__pyx_v_parser);
 
2530
  __Pyx_XGIVEREF(__pyx_r);
 
2531
  __Pyx_RefNannyFinishContext();
 
2532
  return __pyx_r;
 
2533
}
 
2534
 
 
2535
/* "bzrlib/_btree_serializer_pyx.pyx":349
 
2536
 * _hexbuf = '0123456789abcdef'
 
2537
 * 
 
2538
 * cdef _populate_unhexbuf():             # <<<<<<<<<<<<<<
 
2539
 *     cdef int i
 
2540
 *     for i from 0 <= i < 256:
 
2541
 */
 
2542
 
 
2543
static  PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__populate_unhexbuf(void) {
 
2544
  int __pyx_v_i;
 
2545
  PyObject *__pyx_r = NULL;
 
2546
  __Pyx_RefNannySetupContext("_populate_unhexbuf");
 
2547
 
 
2548
  /* "bzrlib/_btree_serializer_pyx.pyx":351
 
2549
 * cdef _populate_unhexbuf():
 
2550
 *     cdef int i
 
2551
 *     for i from 0 <= i < 256:             # <<<<<<<<<<<<<<
 
2552
 *         _unhexbuf[i] = -1
 
2553
 *     for i from 0 <= i < 10: # 0123456789 => map to the raw number
 
2554
 */
 
2555
  for (__pyx_v_i = 0; __pyx_v_i < 256; __pyx_v_i++) {
 
2556
 
 
2557
    /* "bzrlib/_btree_serializer_pyx.pyx":352
 
2558
 *     cdef int i
 
2559
 *     for i from 0 <= i < 256:
 
2560
 *         _unhexbuf[i] = -1             # <<<<<<<<<<<<<<
 
2561
 *     for i from 0 <= i < 10: # 0123456789 => map to the raw number
 
2562
 *         _unhexbuf[(i + c'0')] = i
 
2563
 */
 
2564
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[__pyx_v_i]) = -1;
 
2565
  }
 
2566
 
 
2567
  /* "bzrlib/_btree_serializer_pyx.pyx":353
 
2568
 *     for i from 0 <= i < 256:
 
2569
 *         _unhexbuf[i] = -1
 
2570
 *     for i from 0 <= i < 10: # 0123456789 => map to the raw number             # <<<<<<<<<<<<<<
 
2571
 *         _unhexbuf[(i + c'0')] = i
 
2572
 *     for i from 10 <= i < 16: # abcdef => 10, 11, 12, 13, 14, 15, 16
 
2573
 */
 
2574
  for (__pyx_v_i = 0; __pyx_v_i < 10; __pyx_v_i++) {
 
2575
 
 
2576
    /* "bzrlib/_btree_serializer_pyx.pyx":354
 
2577
 *         _unhexbuf[i] = -1
 
2578
 *     for i from 0 <= i < 10: # 0123456789 => map to the raw number
 
2579
 *         _unhexbuf[(i + c'0')] = i             # <<<<<<<<<<<<<<
 
2580
 *     for i from 10 <= i < 16: # abcdef => 10, 11, 12, 13, 14, 15, 16
 
2581
 *         _unhexbuf[(i - 10 + c'a')] = i
 
2582
 */
 
2583
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[(__pyx_v_i + '0')]) = __pyx_v_i;
 
2584
  }
 
2585
 
 
2586
  /* "bzrlib/_btree_serializer_pyx.pyx":355
 
2587
 *     for i from 0 <= i < 10: # 0123456789 => map to the raw number
 
2588
 *         _unhexbuf[(i + c'0')] = i
 
2589
 *     for i from 10 <= i < 16: # abcdef => 10, 11, 12, 13, 14, 15, 16             # <<<<<<<<<<<<<<
 
2590
 *         _unhexbuf[(i - 10 + c'a')] = i
 
2591
 *     for i from 10 <= i < 16: # ABCDEF => 10, 11, 12, 13, 14, 15, 16
 
2592
 */
 
2593
  for (__pyx_v_i = 10; __pyx_v_i < 16; __pyx_v_i++) {
 
2594
 
 
2595
    /* "bzrlib/_btree_serializer_pyx.pyx":356
 
2596
 *         _unhexbuf[(i + c'0')] = i
 
2597
 *     for i from 10 <= i < 16: # abcdef => 10, 11, 12, 13, 14, 15, 16
 
2598
 *         _unhexbuf[(i - 10 + c'a')] = i             # <<<<<<<<<<<<<<
 
2599
 *     for i from 10 <= i < 16: # ABCDEF => 10, 11, 12, 13, 14, 15, 16
 
2600
 *         _unhexbuf[(i - 10 + c'A')] = i
 
2601
 */
 
2602
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((__pyx_v_i - 10) + 'a')]) = __pyx_v_i;
 
2603
  }
 
2604
 
 
2605
  /* "bzrlib/_btree_serializer_pyx.pyx":357
 
2606
 *     for i from 10 <= i < 16: # abcdef => 10, 11, 12, 13, 14, 15, 16
 
2607
 *         _unhexbuf[(i - 10 + c'a')] = i
 
2608
 *     for i from 10 <= i < 16: # ABCDEF => 10, 11, 12, 13, 14, 15, 16             # <<<<<<<<<<<<<<
 
2609
 *         _unhexbuf[(i - 10 + c'A')] = i
 
2610
 * _populate_unhexbuf()
 
2611
 */
 
2612
  for (__pyx_v_i = 10; __pyx_v_i < 16; __pyx_v_i++) {
 
2613
 
 
2614
    /* "bzrlib/_btree_serializer_pyx.pyx":358
 
2615
 *         _unhexbuf[(i - 10 + c'a')] = i
 
2616
 *     for i from 10 <= i < 16: # ABCDEF => 10, 11, 12, 13, 14, 15, 16
 
2617
 *         _unhexbuf[(i - 10 + c'A')] = i             # <<<<<<<<<<<<<<
 
2618
 * _populate_unhexbuf()
 
2619
 * 
 
2620
 */
 
2621
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((__pyx_v_i - 10) + 'A')]) = __pyx_v_i;
 
2622
  }
 
2623
 
 
2624
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
2625
  __Pyx_XGIVEREF(__pyx_r);
 
2626
  __Pyx_RefNannyFinishContext();
 
2627
  return __pyx_r;
 
2628
}
 
2629
 
 
2630
/* "bzrlib/_btree_serializer_pyx.pyx":362
 
2631
 * 
 
2632
 * 
 
2633
 * cdef int _unhexlify_sha1(char *as_hex, char *as_bin): # cannot_raise             # <<<<<<<<<<<<<<
 
2634
 *     """Take the hex sha1 in as_hex and make it binary in as_bin
 
2635
 * 
 
2636
 */
 
2637
 
 
2638
static  int __pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(char *__pyx_v_as_hex, char *__pyx_v_as_bin) {
 
2639
  int __pyx_v_top;
 
2640
  int __pyx_v_bot;
 
2641
  int __pyx_v_i;
 
2642
  int __pyx_v_j;
 
2643
  int __pyx_r;
 
2644
  int __pyx_t_1;
 
2645
  int __pyx_t_2;
 
2646
  int __pyx_t_3;
 
2647
  __Pyx_RefNannySetupContext("_unhexlify_sha1");
 
2648
 
 
2649
  /* "bzrlib/_btree_serializer_pyx.pyx":374
 
2650
 *     # binascii does this using isupper() and tolower() and ?: syntax. I'm
 
2651
 *     # guessing a simple lookup array should be faster.
 
2652
 *     j = 0             # <<<<<<<<<<<<<<
 
2653
 *     for i from 0 <= i < 20:
 
2654
 *         top = _unhexbuf[<unsigned char>(as_hex[j])]
 
2655
 */
 
2656
  __pyx_v_j = 0;
 
2657
 
 
2658
  /* "bzrlib/_btree_serializer_pyx.pyx":375
 
2659
 *     # guessing a simple lookup array should be faster.
 
2660
 *     j = 0
 
2661
 *     for i from 0 <= i < 20:             # <<<<<<<<<<<<<<
 
2662
 *         top = _unhexbuf[<unsigned char>(as_hex[j])]
 
2663
 *         j = j + 1
 
2664
 */
 
2665
  for (__pyx_v_i = 0; __pyx_v_i < 20; __pyx_v_i++) {
 
2666
 
 
2667
    /* "bzrlib/_btree_serializer_pyx.pyx":376
 
2668
 *     j = 0
 
2669
 *     for i from 0 <= i < 20:
 
2670
 *         top = _unhexbuf[<unsigned char>(as_hex[j])]             # <<<<<<<<<<<<<<
 
2671
 *         j = j + 1
 
2672
 *         bot = _unhexbuf[<unsigned char>(as_hex[j])]
 
2673
 */
 
2674
    __pyx_v_top = (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((unsigned char)(__pyx_v_as_hex[__pyx_v_j]))]);
 
2675
 
 
2676
    /* "bzrlib/_btree_serializer_pyx.pyx":377
 
2677
 *     for i from 0 <= i < 20:
 
2678
 *         top = _unhexbuf[<unsigned char>(as_hex[j])]
 
2679
 *         j = j + 1             # <<<<<<<<<<<<<<
 
2680
 *         bot = _unhexbuf[<unsigned char>(as_hex[j])]
 
2681
 *         j = j + 1
 
2682
 */
 
2683
    __pyx_v_j = (__pyx_v_j + 1);
 
2684
 
 
2685
    /* "bzrlib/_btree_serializer_pyx.pyx":378
 
2686
 *         top = _unhexbuf[<unsigned char>(as_hex[j])]
 
2687
 *         j = j + 1
 
2688
 *         bot = _unhexbuf[<unsigned char>(as_hex[j])]             # <<<<<<<<<<<<<<
 
2689
 *         j = j + 1
 
2690
 *         if top == -1 or bot == -1:
 
2691
 */
 
2692
    __pyx_v_bot = (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((unsigned char)(__pyx_v_as_hex[__pyx_v_j]))]);
 
2693
 
 
2694
    /* "bzrlib/_btree_serializer_pyx.pyx":379
 
2695
 *         j = j + 1
 
2696
 *         bot = _unhexbuf[<unsigned char>(as_hex[j])]
 
2697
 *         j = j + 1             # <<<<<<<<<<<<<<
 
2698
 *         if top == -1 or bot == -1:
 
2699
 *             return 0
 
2700
 */
 
2701
    __pyx_v_j = (__pyx_v_j + 1);
 
2702
 
 
2703
    /* "bzrlib/_btree_serializer_pyx.pyx":380
 
2704
 *         bot = _unhexbuf[<unsigned char>(as_hex[j])]
 
2705
 *         j = j + 1
 
2706
 *         if top == -1 or bot == -1:             # <<<<<<<<<<<<<<
 
2707
 *             return 0
 
2708
 *         as_bin[i] = <unsigned char>((top << 4) + bot);
 
2709
 */
 
2710
    __pyx_t_1 = (__pyx_v_top == -1);
 
2711
    if (!__pyx_t_1) {
 
2712
      __pyx_t_2 = (__pyx_v_bot == -1);
 
2713
      __pyx_t_3 = __pyx_t_2;
 
2714
    } else {
 
2715
      __pyx_t_3 = __pyx_t_1;
 
2716
    }
 
2717
    if (__pyx_t_3) {
 
2718
 
 
2719
      /* "bzrlib/_btree_serializer_pyx.pyx":381
 
2720
 *         j = j + 1
 
2721
 *         if top == -1 or bot == -1:
 
2722
 *             return 0             # <<<<<<<<<<<<<<
 
2723
 *         as_bin[i] = <unsigned char>((top << 4) + bot);
 
2724
 *     return 1
 
2725
 */
 
2726
      __pyx_r = 0;
 
2727
      goto __pyx_L0;
 
2728
      goto __pyx_L5;
 
2729
    }
 
2730
    __pyx_L5:;
 
2731
 
 
2732
    /* "bzrlib/_btree_serializer_pyx.pyx":382
 
2733
 *         if top == -1 or bot == -1:
 
2734
 *             return 0
 
2735
 *         as_bin[i] = <unsigned char>((top << 4) + bot);             # <<<<<<<<<<<<<<
 
2736
 *     return 1
 
2737
 * 
 
2738
 */
 
2739
    (__pyx_v_as_bin[__pyx_v_i]) = ((unsigned char)((__pyx_v_top << 4) + __pyx_v_bot));
 
2740
  }
 
2741
 
 
2742
  /* "bzrlib/_btree_serializer_pyx.pyx":383
 
2743
 *             return 0
 
2744
 *         as_bin[i] = <unsigned char>((top << 4) + bot);
 
2745
 *     return 1             # <<<<<<<<<<<<<<
 
2746
 * 
 
2747
 * 
 
2748
 */
 
2749
  __pyx_r = 1;
 
2750
  goto __pyx_L0;
 
2751
 
 
2752
  __pyx_r = 0;
 
2753
  __pyx_L0:;
 
2754
  __Pyx_RefNannyFinishContext();
 
2755
  return __pyx_r;
 
2756
}
 
2757
 
 
2758
/* "bzrlib/_btree_serializer_pyx.pyx":386
 
2759
 * 
 
2760
 * 
 
2761
 * def _py_unhexlify(as_hex):             # <<<<<<<<<<<<<<
 
2762
 *     """For the test infrastructure, just thunks to _unhexlify_sha1"""
 
2763
 *     if len(as_hex) != 40 or not PyString_CheckExact(as_hex):
 
2764
 */
 
2765
 
 
2766
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_1_py_unhexlify(PyObject *__pyx_self, PyObject *__pyx_v_as_hex); /*proto*/
 
2767
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx_1_py_unhexlify[] = "For the test infrastructure, just thunks to _unhexlify_sha1";
 
2768
static PyMethodDef __pyx_mdef_6bzrlib_21_btree_serializer_pyx_1_py_unhexlify = {__Pyx_NAMESTR("_py_unhexlify"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_1_py_unhexlify, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_21_btree_serializer_pyx_1_py_unhexlify)};
 
2769
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_1_py_unhexlify(PyObject *__pyx_self, PyObject *__pyx_v_as_hex) {
 
2770
  PyObject *__pyx_v_as_bin;
 
2771
  PyObject *__pyx_r = NULL;
 
2772
  Py_ssize_t __pyx_t_1;
 
2773
  int __pyx_t_2;
 
2774
  int __pyx_t_3;
 
2775
  int __pyx_t_4;
 
2776
  PyObject *__pyx_t_5 = NULL;
 
2777
  int __pyx_t_6;
 
2778
  __Pyx_RefNannySetupContext("_py_unhexlify");
 
2779
  __pyx_self = __pyx_self;
 
2780
  __pyx_v_as_bin = Py_None; __Pyx_INCREF(Py_None);
 
2781
 
 
2782
  /* "bzrlib/_btree_serializer_pyx.pyx":388
 
2783
 * def _py_unhexlify(as_hex):
 
2784
 *     """For the test infrastructure, just thunks to _unhexlify_sha1"""
 
2785
 *     if len(as_hex) != 40 or not PyString_CheckExact(as_hex):             # <<<<<<<<<<<<<<
 
2786
 *         raise ValueError('not a 40-byte hex digest')
 
2787
 *     as_bin = PyString_FromStringAndSize(NULL, 20)
 
2788
 */
 
2789
  __pyx_t_1 = PyObject_Length(__pyx_v_as_hex); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2790
  __pyx_t_2 = (__pyx_t_1 != 40);
 
2791
  if (!__pyx_t_2) {
 
2792
    __pyx_t_3 = (!PyString_CheckExact(__pyx_v_as_hex));
 
2793
    __pyx_t_4 = __pyx_t_3;
 
2794
  } else {
 
2795
    __pyx_t_4 = __pyx_t_2;
 
2796
  }
 
2797
  if (__pyx_t_4) {
 
2798
 
 
2799
    /* "bzrlib/_btree_serializer_pyx.pyx":389
 
2800
 *     """For the test infrastructure, just thunks to _unhexlify_sha1"""
 
2801
 *     if len(as_hex) != 40 or not PyString_CheckExact(as_hex):
 
2802
 *         raise ValueError('not a 40-byte hex digest')             # <<<<<<<<<<<<<<
 
2803
 *     as_bin = PyString_FromStringAndSize(NULL, 20)
 
2804
 *     if _unhexlify_sha1(PyString_AS_STRING(as_hex), PyString_AS_STRING(as_bin)):
 
2805
 */
 
2806
    __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2807
    __Pyx_GOTREF(__pyx_t_5);
 
2808
    __Pyx_Raise(__pyx_t_5, 0, 0);
 
2809
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
2810
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2811
    goto __pyx_L5;
 
2812
  }
 
2813
  __pyx_L5:;
 
2814
 
 
2815
  /* "bzrlib/_btree_serializer_pyx.pyx":390
 
2816
 *     if len(as_hex) != 40 or not PyString_CheckExact(as_hex):
 
2817
 *         raise ValueError('not a 40-byte hex digest')
 
2818
 *     as_bin = PyString_FromStringAndSize(NULL, 20)             # <<<<<<<<<<<<<<
 
2819
 *     if _unhexlify_sha1(PyString_AS_STRING(as_hex), PyString_AS_STRING(as_bin)):
 
2820
 *         return as_bin
 
2821
 */
 
2822
  __pyx_t_5 = PyString_FromStringAndSize(NULL, 20); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2823
  __Pyx_GOTREF(__pyx_t_5);
 
2824
  __Pyx_DECREF(__pyx_v_as_bin);
 
2825
  __pyx_v_as_bin = __pyx_t_5;
 
2826
  __pyx_t_5 = 0;
 
2827
 
 
2828
  /* "bzrlib/_btree_serializer_pyx.pyx":391
 
2829
 *         raise ValueError('not a 40-byte hex digest')
 
2830
 *     as_bin = PyString_FromStringAndSize(NULL, 20)
 
2831
 *     if _unhexlify_sha1(PyString_AS_STRING(as_hex), PyString_AS_STRING(as_bin)):             # <<<<<<<<<<<<<<
 
2832
 *         return as_bin
 
2833
 *     return None
 
2834
 */
 
2835
  __pyx_t_6 = __pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(PyString_AS_STRING(__pyx_v_as_hex), PyString_AS_STRING(__pyx_v_as_bin));
 
2836
  if (__pyx_t_6) {
 
2837
 
 
2838
    /* "bzrlib/_btree_serializer_pyx.pyx":392
 
2839
 *     as_bin = PyString_FromStringAndSize(NULL, 20)
 
2840
 *     if _unhexlify_sha1(PyString_AS_STRING(as_hex), PyString_AS_STRING(as_bin)):
 
2841
 *         return as_bin             # <<<<<<<<<<<<<<
 
2842
 *     return None
 
2843
 * 
 
2844
 */
 
2845
    __Pyx_XDECREF(__pyx_r);
 
2846
    __Pyx_INCREF(__pyx_v_as_bin);
 
2847
    __pyx_r = __pyx_v_as_bin;
 
2848
    goto __pyx_L0;
 
2849
    goto __pyx_L6;
 
2850
  }
 
2851
  __pyx_L6:;
 
2852
 
 
2853
  /* "bzrlib/_btree_serializer_pyx.pyx":393
 
2854
 *     if _unhexlify_sha1(PyString_AS_STRING(as_hex), PyString_AS_STRING(as_bin)):
 
2855
 *         return as_bin
 
2856
 *     return None             # <<<<<<<<<<<<<<
 
2857
 * 
 
2858
 * 
 
2859
 */
 
2860
  __Pyx_XDECREF(__pyx_r);
 
2861
  __Pyx_INCREF(Py_None);
 
2862
  __pyx_r = Py_None;
 
2863
  goto __pyx_L0;
 
2864
 
 
2865
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
2866
  goto __pyx_L0;
 
2867
  __pyx_L1_error:;
 
2868
  __Pyx_XDECREF(__pyx_t_5);
 
2869
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_unhexlify");
 
2870
  __pyx_r = NULL;
 
2871
  __pyx_L0:;
 
2872
  __Pyx_DECREF(__pyx_v_as_bin);
 
2873
  __Pyx_XGIVEREF(__pyx_r);
 
2874
  __Pyx_RefNannyFinishContext();
 
2875
  return __pyx_r;
 
2876
}
 
2877
 
 
2878
/* "bzrlib/_btree_serializer_pyx.pyx":396
 
2879
 * 
 
2880
 * 
 
2881
 * cdef void _hexlify_sha1(char *as_bin, char *as_hex): # cannot_raise             # <<<<<<<<<<<<<<
 
2882
 *     cdef int i, j
 
2883
 *     cdef char c
 
2884
 */
 
2885
 
 
2886
static  void __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(char *__pyx_v_as_bin, char *__pyx_v_as_hex) {
 
2887
  int __pyx_v_i;
 
2888
  int __pyx_v_j;
 
2889
  char __pyx_v_c;
 
2890
  __Pyx_RefNannySetupContext("_hexlify_sha1");
 
2891
 
 
2892
  /* "bzrlib/_btree_serializer_pyx.pyx":400
 
2893
 *     cdef char c
 
2894
 * 
 
2895
 *     j = 0             # <<<<<<<<<<<<<<
 
2896
 *     for i from 0 <= i < 20:
 
2897
 *         c = as_bin[i]
 
2898
 */
 
2899
  __pyx_v_j = 0;
 
2900
 
 
2901
  /* "bzrlib/_btree_serializer_pyx.pyx":401
 
2902
 * 
 
2903
 *     j = 0
 
2904
 *     for i from 0 <= i < 20:             # <<<<<<<<<<<<<<
 
2905
 *         c = as_bin[i]
 
2906
 *         as_hex[j] = _hexbuf[(c>>4)&0xf]
 
2907
 */
 
2908
  for (__pyx_v_i = 0; __pyx_v_i < 20; __pyx_v_i++) {
 
2909
 
 
2910
    /* "bzrlib/_btree_serializer_pyx.pyx":402
 
2911
 *     j = 0
 
2912
 *     for i from 0 <= i < 20:
 
2913
 *         c = as_bin[i]             # <<<<<<<<<<<<<<
 
2914
 *         as_hex[j] = _hexbuf[(c>>4)&0xf]
 
2915
 *         j = j + 1
 
2916
 */
 
2917
    __pyx_v_c = (__pyx_v_as_bin[__pyx_v_i]);
 
2918
 
 
2919
    /* "bzrlib/_btree_serializer_pyx.pyx":403
 
2920
 *     for i from 0 <= i < 20:
 
2921
 *         c = as_bin[i]
 
2922
 *         as_hex[j] = _hexbuf[(c>>4)&0xf]             # <<<<<<<<<<<<<<
 
2923
 *         j = j + 1
 
2924
 *         as_hex[j] = _hexbuf[(c)&0xf]
 
2925
 */
 
2926
    (__pyx_v_as_hex[__pyx_v_j]) = (__pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf[((__pyx_v_c >> 4) & 0xf)]);
 
2927
 
 
2928
    /* "bzrlib/_btree_serializer_pyx.pyx":404
 
2929
 *         c = as_bin[i]
 
2930
 *         as_hex[j] = _hexbuf[(c>>4)&0xf]
 
2931
 *         j = j + 1             # <<<<<<<<<<<<<<
 
2932
 *         as_hex[j] = _hexbuf[(c)&0xf]
 
2933
 *         j = j + 1
 
2934
 */
 
2935
    __pyx_v_j = (__pyx_v_j + 1);
 
2936
 
 
2937
    /* "bzrlib/_btree_serializer_pyx.pyx":405
 
2938
 *         as_hex[j] = _hexbuf[(c>>4)&0xf]
 
2939
 *         j = j + 1
 
2940
 *         as_hex[j] = _hexbuf[(c)&0xf]             # <<<<<<<<<<<<<<
 
2941
 *         j = j + 1
 
2942
 * 
 
2943
 */
 
2944
    (__pyx_v_as_hex[__pyx_v_j]) = (__pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf[(__pyx_v_c & 0xf)]);
 
2945
 
 
2946
    /* "bzrlib/_btree_serializer_pyx.pyx":406
 
2947
 *         j = j + 1
 
2948
 *         as_hex[j] = _hexbuf[(c)&0xf]
 
2949
 *         j = j + 1             # <<<<<<<<<<<<<<
 
2950
 * 
 
2951
 * 
 
2952
 */
 
2953
    __pyx_v_j = (__pyx_v_j + 1);
 
2954
  }
 
2955
 
 
2956
  __Pyx_RefNannyFinishContext();
 
2957
}
 
2958
 
 
2959
/* "bzrlib/_btree_serializer_pyx.pyx":409
 
2960
 * 
 
2961
 * 
 
2962
 * def _py_hexlify(as_bin):             # <<<<<<<<<<<<<<
 
2963
 *     """For test infrastructure, thunk to _hexlify_sha1"""
 
2964
 *     if len(as_bin) != 20 or not PyString_CheckExact(as_bin):
 
2965
 */
 
2966
 
 
2967
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_2_py_hexlify(PyObject *__pyx_self, PyObject *__pyx_v_as_bin); /*proto*/
 
2968
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx_2_py_hexlify[] = "For test infrastructure, thunk to _hexlify_sha1";
 
2969
static PyMethodDef __pyx_mdef_6bzrlib_21_btree_serializer_pyx_2_py_hexlify = {__Pyx_NAMESTR("_py_hexlify"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_2_py_hexlify, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_21_btree_serializer_pyx_2_py_hexlify)};
 
2970
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_2_py_hexlify(PyObject *__pyx_self, PyObject *__pyx_v_as_bin) {
 
2971
  PyObject *__pyx_v_as_hex;
 
2972
  PyObject *__pyx_r = NULL;
 
2973
  Py_ssize_t __pyx_t_1;
 
2974
  int __pyx_t_2;
 
2975
  int __pyx_t_3;
 
2976
  int __pyx_t_4;
 
2977
  PyObject *__pyx_t_5 = NULL;
 
2978
  __Pyx_RefNannySetupContext("_py_hexlify");
 
2979
  __pyx_self = __pyx_self;
 
2980
  __pyx_v_as_hex = Py_None; __Pyx_INCREF(Py_None);
 
2981
 
 
2982
  /* "bzrlib/_btree_serializer_pyx.pyx":411
 
2983
 * def _py_hexlify(as_bin):
 
2984
 *     """For test infrastructure, thunk to _hexlify_sha1"""
 
2985
 *     if len(as_bin) != 20 or not PyString_CheckExact(as_bin):             # <<<<<<<<<<<<<<
 
2986
 *         raise ValueError('not a 20-byte binary digest')
 
2987
 *     as_hex = PyString_FromStringAndSize(NULL, 40)
 
2988
 */
 
2989
  __pyx_t_1 = PyObject_Length(__pyx_v_as_bin); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
2990
  __pyx_t_2 = (__pyx_t_1 != 20);
 
2991
  if (!__pyx_t_2) {
 
2992
    __pyx_t_3 = (!PyString_CheckExact(__pyx_v_as_bin));
 
2993
    __pyx_t_4 = __pyx_t_3;
 
2994
  } else {
 
2995
    __pyx_t_4 = __pyx_t_2;
 
2996
  }
 
2997
  if (__pyx_t_4) {
 
2998
 
 
2999
    /* "bzrlib/_btree_serializer_pyx.pyx":412
 
3000
 *     """For test infrastructure, thunk to _hexlify_sha1"""
 
3001
 *     if len(as_bin) != 20 or not PyString_CheckExact(as_bin):
 
3002
 *         raise ValueError('not a 20-byte binary digest')             # <<<<<<<<<<<<<<
 
3003
 *     as_hex = PyString_FromStringAndSize(NULL, 40)
 
3004
 *     _hexlify_sha1(PyString_AS_STRING(as_bin), PyString_AS_STRING(as_hex))
 
3005
 */
 
3006
    __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3007
    __Pyx_GOTREF(__pyx_t_5);
 
3008
    __Pyx_Raise(__pyx_t_5, 0, 0);
 
3009
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
3010
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3011
    goto __pyx_L5;
 
3012
  }
 
3013
  __pyx_L5:;
 
3014
 
 
3015
  /* "bzrlib/_btree_serializer_pyx.pyx":413
 
3016
 *     if len(as_bin) != 20 or not PyString_CheckExact(as_bin):
 
3017
 *         raise ValueError('not a 20-byte binary digest')
 
3018
 *     as_hex = PyString_FromStringAndSize(NULL, 40)             # <<<<<<<<<<<<<<
 
3019
 *     _hexlify_sha1(PyString_AS_STRING(as_bin), PyString_AS_STRING(as_hex))
 
3020
 *     return as_hex
 
3021
 */
 
3022
  __pyx_t_5 = PyString_FromStringAndSize(NULL, 40); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3023
  __Pyx_GOTREF(__pyx_t_5);
 
3024
  __Pyx_DECREF(__pyx_v_as_hex);
 
3025
  __pyx_v_as_hex = __pyx_t_5;
 
3026
  __pyx_t_5 = 0;
 
3027
 
 
3028
  /* "bzrlib/_btree_serializer_pyx.pyx":414
 
3029
 *         raise ValueError('not a 20-byte binary digest')
 
3030
 *     as_hex = PyString_FromStringAndSize(NULL, 40)
 
3031
 *     _hexlify_sha1(PyString_AS_STRING(as_bin), PyString_AS_STRING(as_hex))             # <<<<<<<<<<<<<<
 
3032
 *     return as_hex
 
3033
 * 
 
3034
 */
 
3035
  __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(PyString_AS_STRING(__pyx_v_as_bin), PyString_AS_STRING(__pyx_v_as_hex));
 
3036
 
 
3037
  /* "bzrlib/_btree_serializer_pyx.pyx":415
 
3038
 *     as_hex = PyString_FromStringAndSize(NULL, 40)
 
3039
 *     _hexlify_sha1(PyString_AS_STRING(as_bin), PyString_AS_STRING(as_hex))
 
3040
 *     return as_hex             # <<<<<<<<<<<<<<
 
3041
 * 
 
3042
 * 
 
3043
 */
 
3044
  __Pyx_XDECREF(__pyx_r);
 
3045
  __Pyx_INCREF(__pyx_v_as_hex);
 
3046
  __pyx_r = __pyx_v_as_hex;
 
3047
  goto __pyx_L0;
 
3048
 
 
3049
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
3050
  goto __pyx_L0;
 
3051
  __pyx_L1_error:;
 
3052
  __Pyx_XDECREF(__pyx_t_5);
 
3053
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_hexlify");
 
3054
  __pyx_r = NULL;
 
3055
  __pyx_L0:;
 
3056
  __Pyx_DECREF(__pyx_v_as_hex);
 
3057
  __Pyx_XGIVEREF(__pyx_r);
 
3058
  __Pyx_RefNannyFinishContext();
 
3059
  return __pyx_r;
 
3060
}
 
3061
 
 
3062
/* "bzrlib/_btree_serializer_pyx.pyx":418
 
3063
 * 
 
3064
 * 
 
3065
 * cdef int _key_to_sha1(key, char *sha1): # cannot_raise             # <<<<<<<<<<<<<<
 
3066
 *     """Map a key into its sha1 content.
 
3067
 * 
 
3068
 */
 
3069
 
 
3070
static  int __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(PyObject *__pyx_v_key, char *__pyx_v_sha1) {
 
3071
  char *__pyx_v_c_val;
 
3072
  PyObject *__pyx_v_p_val;
 
3073
  int __pyx_r;
 
3074
  int __pyx_t_1;
 
3075
  int __pyx_t_2;
 
3076
  __Pyx_RefNannySetupContext("_key_to_sha1");
 
3077
 
 
3078
  /* "bzrlib/_btree_serializer_pyx.pyx":428
 
3079
 *     cdef PyObject *p_val
 
3080
 * 
 
3081
 *     if StaticTuple_CheckExact(key) and StaticTuple_GET_SIZE(key) == 1:             # <<<<<<<<<<<<<<
 
3082
 *         p_val = <PyObject *>StaticTuple_GET_ITEM(key, 0)
 
3083
 *     elif (PyTuple_CheckExact(key) and PyTuple_GET_SIZE(key) == 1):
 
3084
 */
 
3085
  if (StaticTuple_CheckExact(__pyx_v_key)) {
 
3086
    if (!(likely(((__pyx_v_key) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_key, __pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3087
    __pyx_t_1 = (StaticTuple_GET_SIZE(((StaticTuple *)__pyx_v_key)) == 1);
 
3088
    __pyx_t_2 = __pyx_t_1;
 
3089
  } else {
 
3090
    __pyx_t_2 = StaticTuple_CheckExact(__pyx_v_key);
 
3091
  }
 
3092
  if (__pyx_t_2) {
 
3093
 
 
3094
    /* "bzrlib/_btree_serializer_pyx.pyx":429
 
3095
 * 
 
3096
 *     if StaticTuple_CheckExact(key) and StaticTuple_GET_SIZE(key) == 1:
 
3097
 *         p_val = <PyObject *>StaticTuple_GET_ITEM(key, 0)             # <<<<<<<<<<<<<<
 
3098
 *     elif (PyTuple_CheckExact(key) and PyTuple_GET_SIZE(key) == 1):
 
3099
 *         p_val = PyTuple_GET_ITEM_ptr_object(key, 0)
 
3100
 */
 
3101
    if (!(likely(((__pyx_v_key) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_key, __pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3102
    __pyx_v_p_val = ((PyObject *)StaticTuple_GET_ITEM(((StaticTuple *)__pyx_v_key), 0));
 
3103
    goto __pyx_L3;
 
3104
  }
 
3105
 
 
3106
  /* "bzrlib/_btree_serializer_pyx.pyx":430
 
3107
 *     if StaticTuple_CheckExact(key) and StaticTuple_GET_SIZE(key) == 1:
 
3108
 *         p_val = <PyObject *>StaticTuple_GET_ITEM(key, 0)
 
3109
 *     elif (PyTuple_CheckExact(key) and PyTuple_GET_SIZE(key) == 1):             # <<<<<<<<<<<<<<
 
3110
 *         p_val = PyTuple_GET_ITEM_ptr_object(key, 0)
 
3111
 *     else:
 
3112
 */
 
3113
  if (PyTuple_CheckExact(__pyx_v_key)) {
 
3114
    __pyx_t_2 = (PyTuple_GET_SIZE(__pyx_v_key) == 1);
 
3115
    __pyx_t_1 = __pyx_t_2;
 
3116
  } else {
 
3117
    __pyx_t_1 = PyTuple_CheckExact(__pyx_v_key);
 
3118
  }
 
3119
  if (__pyx_t_1) {
 
3120
 
 
3121
    /* "bzrlib/_btree_serializer_pyx.pyx":431
 
3122
 *         p_val = <PyObject *>StaticTuple_GET_ITEM(key, 0)
 
3123
 *     elif (PyTuple_CheckExact(key) and PyTuple_GET_SIZE(key) == 1):
 
3124
 *         p_val = PyTuple_GET_ITEM_ptr_object(key, 0)             # <<<<<<<<<<<<<<
 
3125
 *     else:
 
3126
 *         # Not a tuple or a StaticTuple
 
3127
 */
 
3128
    __pyx_v_p_val = PyTuple_GET_ITEM(__pyx_v_key, 0);
 
3129
    goto __pyx_L3;
 
3130
  }
 
3131
  /*else*/ {
 
3132
 
 
3133
    /* "bzrlib/_btree_serializer_pyx.pyx":434
 
3134
 *     else:
 
3135
 *         # Not a tuple or a StaticTuple
 
3136
 *         return 0             # <<<<<<<<<<<<<<
 
3137
 *     if (PyString_CheckExact_ptr(p_val) and PyString_GET_SIZE_ptr(p_val) == 45):
 
3138
 *         c_val = PyString_AS_STRING_ptr(p_val)
 
3139
 */
 
3140
    __pyx_r = 0;
 
3141
    goto __pyx_L0;
 
3142
  }
 
3143
  __pyx_L3:;
 
3144
 
 
3145
  /* "bzrlib/_btree_serializer_pyx.pyx":435
 
3146
 *         # Not a tuple or a StaticTuple
 
3147
 *         return 0
 
3148
 *     if (PyString_CheckExact_ptr(p_val) and PyString_GET_SIZE_ptr(p_val) == 45):             # <<<<<<<<<<<<<<
 
3149
 *         c_val = PyString_AS_STRING_ptr(p_val)
 
3150
 *     else:
 
3151
 */
 
3152
  if (PyString_CheckExact(__pyx_v_p_val)) {
 
3153
    __pyx_t_1 = (PyString_GET_SIZE(__pyx_v_p_val) == 45);
 
3154
    __pyx_t_2 = __pyx_t_1;
 
3155
  } else {
 
3156
    __pyx_t_2 = PyString_CheckExact(__pyx_v_p_val);
 
3157
  }
 
3158
  if (__pyx_t_2) {
 
3159
 
 
3160
    /* "bzrlib/_btree_serializer_pyx.pyx":436
 
3161
 *         return 0
 
3162
 *     if (PyString_CheckExact_ptr(p_val) and PyString_GET_SIZE_ptr(p_val) == 45):
 
3163
 *         c_val = PyString_AS_STRING_ptr(p_val)             # <<<<<<<<<<<<<<
 
3164
 *     else:
 
3165
 *         return 0
 
3166
 */
 
3167
    __pyx_v_c_val = PyString_AS_STRING(__pyx_v_p_val);
 
3168
    goto __pyx_L4;
 
3169
  }
 
3170
  /*else*/ {
 
3171
 
 
3172
    /* "bzrlib/_btree_serializer_pyx.pyx":438
 
3173
 *         c_val = PyString_AS_STRING_ptr(p_val)
 
3174
 *     else:
 
3175
 *         return 0             # <<<<<<<<<<<<<<
 
3176
 *     if strncmp(c_val, 'sha1:', 5) != 0:
 
3177
 *         return 0
 
3178
 */
 
3179
    __pyx_r = 0;
 
3180
    goto __pyx_L0;
 
3181
  }
 
3182
  __pyx_L4:;
 
3183
 
 
3184
  /* "bzrlib/_btree_serializer_pyx.pyx":439
 
3185
 *     else:
 
3186
 *         return 0
 
3187
 *     if strncmp(c_val, 'sha1:', 5) != 0:             # <<<<<<<<<<<<<<
 
3188
 *         return 0
 
3189
 *     if not _unhexlify_sha1(c_val + 5, sha1):
 
3190
 */
 
3191
  __pyx_t_2 = (strncmp(__pyx_v_c_val, __pyx_k_3, 5) != 0);
 
3192
  if (__pyx_t_2) {
 
3193
 
 
3194
    /* "bzrlib/_btree_serializer_pyx.pyx":440
 
3195
 *         return 0
 
3196
 *     if strncmp(c_val, 'sha1:', 5) != 0:
 
3197
 *         return 0             # <<<<<<<<<<<<<<
 
3198
 *     if not _unhexlify_sha1(c_val + 5, sha1):
 
3199
 *         return 0
 
3200
 */
 
3201
    __pyx_r = 0;
 
3202
    goto __pyx_L0;
 
3203
    goto __pyx_L5;
 
3204
  }
 
3205
  __pyx_L5:;
 
3206
 
 
3207
  /* "bzrlib/_btree_serializer_pyx.pyx":441
 
3208
 *     if strncmp(c_val, 'sha1:', 5) != 0:
 
3209
 *         return 0
 
3210
 *     if not _unhexlify_sha1(c_val + 5, sha1):             # <<<<<<<<<<<<<<
 
3211
 *         return 0
 
3212
 *     return 1
 
3213
 */
 
3214
  __pyx_t_2 = (!__pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1((__pyx_v_c_val + 5), __pyx_v_sha1));
 
3215
  if (__pyx_t_2) {
 
3216
 
 
3217
    /* "bzrlib/_btree_serializer_pyx.pyx":442
 
3218
 *         return 0
 
3219
 *     if not _unhexlify_sha1(c_val + 5, sha1):
 
3220
 *         return 0             # <<<<<<<<<<<<<<
 
3221
 *     return 1
 
3222
 * 
 
3223
 */
 
3224
    __pyx_r = 0;
 
3225
    goto __pyx_L0;
 
3226
    goto __pyx_L6;
 
3227
  }
 
3228
  __pyx_L6:;
 
3229
 
 
3230
  /* "bzrlib/_btree_serializer_pyx.pyx":443
 
3231
 *     if not _unhexlify_sha1(c_val + 5, sha1):
 
3232
 *         return 0
 
3233
 *     return 1             # <<<<<<<<<<<<<<
 
3234
 * 
 
3235
 * 
 
3236
 */
 
3237
  __pyx_r = 1;
 
3238
  goto __pyx_L0;
 
3239
 
 
3240
  __pyx_r = 0;
 
3241
  goto __pyx_L0;
 
3242
  __pyx_L1_error:;
 
3243
  __Pyx_WriteUnraisable("bzrlib._btree_serializer_pyx._key_to_sha1");
 
3244
  __pyx_r = 0;
 
3245
  __pyx_L0:;
 
3246
  __Pyx_RefNannyFinishContext();
 
3247
  return __pyx_r;
 
3248
}
 
3249
 
 
3250
/* "bzrlib/_btree_serializer_pyx.pyx":446
 
3251
 * 
 
3252
 * 
 
3253
 * def _py_key_to_sha1(key):             # <<<<<<<<<<<<<<
 
3254
 *     """Map a key to a simple sha1 string.
 
3255
 * 
 
3256
 */
 
3257
 
 
3258
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_3_py_key_to_sha1(PyObject *__pyx_self, PyObject *__pyx_v_key); /*proto*/
 
3259
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx_3_py_key_to_sha1[] = "Map a key to a simple sha1 string.\n\n    This is a testing thunk to the C function.\n    ";
 
3260
static PyMethodDef __pyx_mdef_6bzrlib_21_btree_serializer_pyx_3_py_key_to_sha1 = {__Pyx_NAMESTR("_py_key_to_sha1"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_3_py_key_to_sha1, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_21_btree_serializer_pyx_3_py_key_to_sha1)};
 
3261
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_3_py_key_to_sha1(PyObject *__pyx_self, PyObject *__pyx_v_key) {
 
3262
  PyObject *__pyx_v_as_bin_sha;
 
3263
  PyObject *__pyx_r = NULL;
 
3264
  PyObject *__pyx_t_1 = NULL;
 
3265
  int __pyx_t_2;
 
3266
  __Pyx_RefNannySetupContext("_py_key_to_sha1");
 
3267
  __pyx_self = __pyx_self;
 
3268
  __pyx_v_as_bin_sha = Py_None; __Pyx_INCREF(Py_None);
 
3269
 
 
3270
  /* "bzrlib/_btree_serializer_pyx.pyx":451
 
3271
 *     This is a testing thunk to the C function.
 
3272
 *     """
 
3273
 *     as_bin_sha = PyString_FromStringAndSize(NULL, 20)             # <<<<<<<<<<<<<<
 
3274
 *     if _key_to_sha1(key, PyString_AS_STRING(as_bin_sha)):
 
3275
 *         return as_bin_sha
 
3276
 */
 
3277
  __pyx_t_1 = PyString_FromStringAndSize(NULL, 20); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3278
  __Pyx_GOTREF(__pyx_t_1);
 
3279
  __Pyx_DECREF(__pyx_v_as_bin_sha);
 
3280
  __pyx_v_as_bin_sha = __pyx_t_1;
 
3281
  __pyx_t_1 = 0;
 
3282
 
 
3283
  /* "bzrlib/_btree_serializer_pyx.pyx":452
 
3284
 *     """
 
3285
 *     as_bin_sha = PyString_FromStringAndSize(NULL, 20)
 
3286
 *     if _key_to_sha1(key, PyString_AS_STRING(as_bin_sha)):             # <<<<<<<<<<<<<<
 
3287
 *         return as_bin_sha
 
3288
 *     return None
 
3289
 */
 
3290
  __pyx_t_2 = __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(__pyx_v_key, PyString_AS_STRING(__pyx_v_as_bin_sha));
 
3291
  if (__pyx_t_2) {
 
3292
 
 
3293
    /* "bzrlib/_btree_serializer_pyx.pyx":453
 
3294
 *     as_bin_sha = PyString_FromStringAndSize(NULL, 20)
 
3295
 *     if _key_to_sha1(key, PyString_AS_STRING(as_bin_sha)):
 
3296
 *         return as_bin_sha             # <<<<<<<<<<<<<<
 
3297
 *     return None
 
3298
 * 
 
3299
 */
 
3300
    __Pyx_XDECREF(__pyx_r);
 
3301
    __Pyx_INCREF(__pyx_v_as_bin_sha);
 
3302
    __pyx_r = __pyx_v_as_bin_sha;
 
3303
    goto __pyx_L0;
 
3304
    goto __pyx_L5;
 
3305
  }
 
3306
  __pyx_L5:;
 
3307
 
 
3308
  /* "bzrlib/_btree_serializer_pyx.pyx":454
 
3309
 *     if _key_to_sha1(key, PyString_AS_STRING(as_bin_sha)):
 
3310
 *         return as_bin_sha
 
3311
 *     return None             # <<<<<<<<<<<<<<
 
3312
 * 
 
3313
 * 
 
3314
 */
 
3315
  __Pyx_XDECREF(__pyx_r);
 
3316
  __Pyx_INCREF(Py_None);
 
3317
  __pyx_r = Py_None;
 
3318
  goto __pyx_L0;
 
3319
 
 
3320
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
3321
  goto __pyx_L0;
 
3322
  __pyx_L1_error:;
 
3323
  __Pyx_XDECREF(__pyx_t_1);
 
3324
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_key_to_sha1");
 
3325
  __pyx_r = NULL;
 
3326
  __pyx_L0:;
 
3327
  __Pyx_DECREF(__pyx_v_as_bin_sha);
 
3328
  __Pyx_XGIVEREF(__pyx_r);
 
3329
  __Pyx_RefNannyFinishContext();
 
3330
  return __pyx_r;
 
3331
}
 
3332
 
 
3333
/* "bzrlib/_btree_serializer_pyx.pyx":457
 
3334
 * 
 
3335
 * 
 
3336
 * cdef StaticTuple _sha1_to_key(char *sha1):             # <<<<<<<<<<<<<<
 
3337
 *     """Compute a ('sha1:abcd',) key for a given sha1."""
 
3338
 *     cdef StaticTuple key
 
3339
 */
 
3340
 
 
3341
static  StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(char *__pyx_v_sha1) {
 
3342
  StaticTuple *__pyx_v_key;
 
3343
  PyObject *__pyx_v_hexxed;
 
3344
  char *__pyx_v_c_buf;
 
3345
  StaticTuple *__pyx_r = NULL;
 
3346
  PyObject *__pyx_t_1 = NULL;
 
3347
  __Pyx_RefNannySetupContext("_sha1_to_key");
 
3348
  __pyx_v_key = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
3349
  __pyx_v_hexxed = Py_None; __Pyx_INCREF(Py_None);
 
3350
 
 
3351
  /* "bzrlib/_btree_serializer_pyx.pyx":462
 
3352
 *     cdef object hexxed
 
3353
 *     cdef char *c_buf
 
3354
 *     hexxed = PyString_FromStringAndSize(NULL, 45)             # <<<<<<<<<<<<<<
 
3355
 *     c_buf = PyString_AS_STRING(hexxed)
 
3356
 *     memcpy(c_buf, 'sha1:', 5)
 
3357
 */
 
3358
  __pyx_t_1 = PyString_FromStringAndSize(NULL, 45); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3359
  __Pyx_GOTREF(__pyx_t_1);
 
3360
  __Pyx_DECREF(__pyx_v_hexxed);
 
3361
  __pyx_v_hexxed = __pyx_t_1;
 
3362
  __pyx_t_1 = 0;
 
3363
 
 
3364
  /* "bzrlib/_btree_serializer_pyx.pyx":463
 
3365
 *     cdef char *c_buf
 
3366
 *     hexxed = PyString_FromStringAndSize(NULL, 45)
 
3367
 *     c_buf = PyString_AS_STRING(hexxed)             # <<<<<<<<<<<<<<
 
3368
 *     memcpy(c_buf, 'sha1:', 5)
 
3369
 *     _hexlify_sha1(sha1, c_buf+5)
 
3370
 */
 
3371
  __pyx_v_c_buf = PyString_AS_STRING(__pyx_v_hexxed);
 
3372
 
 
3373
  /* "bzrlib/_btree_serializer_pyx.pyx":464
 
3374
 *     hexxed = PyString_FromStringAndSize(NULL, 45)
 
3375
 *     c_buf = PyString_AS_STRING(hexxed)
 
3376
 *     memcpy(c_buf, 'sha1:', 5)             # <<<<<<<<<<<<<<
 
3377
 *     _hexlify_sha1(sha1, c_buf+5)
 
3378
 *     key = StaticTuple_New(1)
 
3379
 */
 
3380
  memcpy(__pyx_v_c_buf, __pyx_k_3, 5);
 
3381
 
 
3382
  /* "bzrlib/_btree_serializer_pyx.pyx":465
 
3383
 *     c_buf = PyString_AS_STRING(hexxed)
 
3384
 *     memcpy(c_buf, 'sha1:', 5)
 
3385
 *     _hexlify_sha1(sha1, c_buf+5)             # <<<<<<<<<<<<<<
 
3386
 *     key = StaticTuple_New(1)
 
3387
 *     Py_INCREF(hexxed)
 
3388
 */
 
3389
  __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(__pyx_v_sha1, (__pyx_v_c_buf + 5));
 
3390
 
 
3391
  /* "bzrlib/_btree_serializer_pyx.pyx":466
 
3392
 *     memcpy(c_buf, 'sha1:', 5)
 
3393
 *     _hexlify_sha1(sha1, c_buf+5)
 
3394
 *     key = StaticTuple_New(1)             # <<<<<<<<<<<<<<
 
3395
 *     Py_INCREF(hexxed)
 
3396
 *     StaticTuple_SET_ITEM(key, 0, hexxed)
 
3397
 */
 
3398
  __pyx_t_1 = ((PyObject *)StaticTuple_New(1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3399
  __Pyx_GOTREF(__pyx_t_1);
 
3400
  __Pyx_DECREF(((PyObject *)__pyx_v_key));
 
3401
  __pyx_v_key = ((StaticTuple *)__pyx_t_1);
 
3402
  __pyx_t_1 = 0;
 
3403
 
 
3404
  /* "bzrlib/_btree_serializer_pyx.pyx":467
 
3405
 *     _hexlify_sha1(sha1, c_buf+5)
 
3406
 *     key = StaticTuple_New(1)
 
3407
 *     Py_INCREF(hexxed)             # <<<<<<<<<<<<<<
 
3408
 *     StaticTuple_SET_ITEM(key, 0, hexxed)
 
3409
 *     # This is a bit expensive. To parse 120 keys takes 48us, to return them all
 
3410
 */
 
3411
  Py_INCREF(__pyx_v_hexxed);
 
3412
 
 
3413
  /* "bzrlib/_btree_serializer_pyx.pyx":468
 
3414
 *     key = StaticTuple_New(1)
 
3415
 *     Py_INCREF(hexxed)
 
3416
 *     StaticTuple_SET_ITEM(key, 0, hexxed)             # <<<<<<<<<<<<<<
 
3417
 *     # This is a bit expensive. To parse 120 keys takes 48us, to return them all
 
3418
 *     # can be done in 66.6us (so 18.6us to build them all).
 
3419
 */
 
3420
  StaticTuple_SET_ITEM(__pyx_v_key, 0, __pyx_v_hexxed);
 
3421
 
 
3422
  /* "bzrlib/_btree_serializer_pyx.pyx":478
 
3423
 *     # We *could* hang the PyObject form off of the gc_chk_sha1_record for ones
 
3424
 *     # that we have deserialized. Something to think about, at least.
 
3425
 *     key = StaticTuple_Intern(key)             # <<<<<<<<<<<<<<
 
3426
 *     return key
 
3427
 * 
 
3428
 */
 
3429
  __pyx_t_1 = ((PyObject *)StaticTuple_Intern(__pyx_v_key)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3430
  __Pyx_GOTREF(__pyx_t_1);
 
3431
  __Pyx_DECREF(((PyObject *)__pyx_v_key));
 
3432
  __pyx_v_key = ((StaticTuple *)__pyx_t_1);
 
3433
  __pyx_t_1 = 0;
 
3434
 
 
3435
  /* "bzrlib/_btree_serializer_pyx.pyx":479
 
3436
 *     # that we have deserialized. Something to think about, at least.
 
3437
 *     key = StaticTuple_Intern(key)
 
3438
 *     return key             # <<<<<<<<<<<<<<
 
3439
 * 
 
3440
 * 
 
3441
 */
 
3442
  __Pyx_XDECREF(((PyObject *)__pyx_r));
 
3443
  __Pyx_INCREF(((PyObject *)__pyx_v_key));
 
3444
  __pyx_r = __pyx_v_key;
 
3445
  goto __pyx_L0;
 
3446
 
 
3447
  __pyx_r = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
3448
  goto __pyx_L0;
 
3449
  __pyx_L1_error:;
 
3450
  __Pyx_XDECREF(__pyx_t_1);
 
3451
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._sha1_to_key");
 
3452
  __pyx_r = 0;
 
3453
  __pyx_L0:;
 
3454
  __Pyx_DECREF((PyObject *)__pyx_v_key);
 
3455
  __Pyx_DECREF(__pyx_v_hexxed);
 
3456
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
 
3457
  __Pyx_RefNannyFinishContext();
 
3458
  return __pyx_r;
 
3459
}
 
3460
 
 
3461
/* "bzrlib/_btree_serializer_pyx.pyx":482
 
3462
 * 
 
3463
 * 
 
3464
 * def _py_sha1_to_key(sha1_bin):             # <<<<<<<<<<<<<<
 
3465
 *     """Test thunk to check the sha1 mapping."""
 
3466
 *     if not PyString_CheckExact(sha1_bin) or PyString_GET_SIZE(sha1_bin) != 20:
 
3467
 */
 
3468
 
 
3469
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_4_py_sha1_to_key(PyObject *__pyx_self, PyObject *__pyx_v_sha1_bin); /*proto*/
 
3470
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx_4_py_sha1_to_key[] = "Test thunk to check the sha1 mapping.";
 
3471
static PyMethodDef __pyx_mdef_6bzrlib_21_btree_serializer_pyx_4_py_sha1_to_key = {__Pyx_NAMESTR("_py_sha1_to_key"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_4_py_sha1_to_key, METH_O, __Pyx_DOCSTR(__pyx_doc_6bzrlib_21_btree_serializer_pyx_4_py_sha1_to_key)};
 
3472
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_4_py_sha1_to_key(PyObject *__pyx_self, PyObject *__pyx_v_sha1_bin) {
 
3473
  PyObject *__pyx_r = NULL;
 
3474
  int __pyx_t_1;
 
3475
  int __pyx_t_2;
 
3476
  int __pyx_t_3;
 
3477
  PyObject *__pyx_t_4 = NULL;
 
3478
  __Pyx_RefNannySetupContext("_py_sha1_to_key");
 
3479
  __pyx_self = __pyx_self;
 
3480
 
 
3481
  /* "bzrlib/_btree_serializer_pyx.pyx":484
 
3482
 * def _py_sha1_to_key(sha1_bin):
 
3483
 *     """Test thunk to check the sha1 mapping."""
 
3484
 *     if not PyString_CheckExact(sha1_bin) or PyString_GET_SIZE(sha1_bin) != 20:             # <<<<<<<<<<<<<<
 
3485
 *         raise ValueError('sha1_bin must be a str of exactly 20 bytes')
 
3486
 *     return _sha1_to_key(PyString_AS_STRING(sha1_bin))
 
3487
 */
 
3488
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_sha1_bin));
 
3489
  if (!__pyx_t_1) {
 
3490
    __pyx_t_2 = (PyString_GET_SIZE(__pyx_v_sha1_bin) != 20);
 
3491
    __pyx_t_3 = __pyx_t_2;
 
3492
  } else {
 
3493
    __pyx_t_3 = __pyx_t_1;
 
3494
  }
 
3495
  if (__pyx_t_3) {
 
3496
 
 
3497
    /* "bzrlib/_btree_serializer_pyx.pyx":485
 
3498
 *     """Test thunk to check the sha1 mapping."""
 
3499
 *     if not PyString_CheckExact(sha1_bin) or PyString_GET_SIZE(sha1_bin) != 20:
 
3500
 *         raise ValueError('sha1_bin must be a str of exactly 20 bytes')             # <<<<<<<<<<<<<<
 
3501
 *     return _sha1_to_key(PyString_AS_STRING(sha1_bin))
 
3502
 * 
 
3503
 */
 
3504
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3505
    __Pyx_GOTREF(__pyx_t_4);
 
3506
    __Pyx_Raise(__pyx_t_4, 0, 0);
 
3507
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
3508
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3509
    goto __pyx_L5;
 
3510
  }
 
3511
  __pyx_L5:;
 
3512
 
 
3513
  /* "bzrlib/_btree_serializer_pyx.pyx":486
 
3514
 *     if not PyString_CheckExact(sha1_bin) or PyString_GET_SIZE(sha1_bin) != 20:
 
3515
 *         raise ValueError('sha1_bin must be a str of exactly 20 bytes')
 
3516
 *     return _sha1_to_key(PyString_AS_STRING(sha1_bin))             # <<<<<<<<<<<<<<
 
3517
 * 
 
3518
 * 
 
3519
 */
 
3520
  __Pyx_XDECREF(__pyx_r);
 
3521
  __pyx_t_4 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(PyString_AS_STRING(__pyx_v_sha1_bin))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3522
  __Pyx_GOTREF(__pyx_t_4);
 
3523
  __pyx_r = __pyx_t_4;
 
3524
  __pyx_t_4 = 0;
 
3525
  goto __pyx_L0;
 
3526
 
 
3527
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
3528
  goto __pyx_L0;
 
3529
  __pyx_L1_error:;
 
3530
  __Pyx_XDECREF(__pyx_t_4);
 
3531
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_sha1_to_key");
 
3532
  __pyx_r = NULL;
 
3533
  __pyx_L0:;
 
3534
  __Pyx_XGIVEREF(__pyx_r);
 
3535
  __Pyx_RefNannyFinishContext();
 
3536
  return __pyx_r;
 
3537
}
 
3538
 
 
3539
/* "bzrlib/_btree_serializer_pyx.pyx":489
 
3540
 * 
 
3541
 * 
 
3542
 * cdef unsigned int _sha1_to_uint(char *sha1): # cannot_raise             # <<<<<<<<<<<<<<
 
3543
 *     cdef unsigned int val
 
3544
 *     # Must be in MSB, because that is how the content is sorted
 
3545
 */
 
3546
 
 
3547
static  unsigned int __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint(char *__pyx_v_sha1) {
 
3548
  unsigned int __pyx_v_val;
 
3549
  unsigned int __pyx_r;
 
3550
  __Pyx_RefNannySetupContext("_sha1_to_uint");
 
3551
 
 
3552
  /* "bzrlib/_btree_serializer_pyx.pyx":495
 
3553
 *            | ((<unsigned int>(sha1[1]) & 0xff) << 16)
 
3554
 *            | ((<unsigned int>(sha1[2]) & 0xff) << 8)
 
3555
 *            | ((<unsigned int>(sha1[3]) & 0xff) << 0))             # <<<<<<<<<<<<<<
 
3556
 *     return val
 
3557
 * 
 
3558
 */
 
3559
  __pyx_v_val = (((((((unsigned int)(__pyx_v_sha1[0])) & 0xff) << 24) | ((((unsigned int)(__pyx_v_sha1[1])) & 0xff) << 16)) | ((((unsigned int)(__pyx_v_sha1[2])) & 0xff) << 8)) | ((((unsigned int)(__pyx_v_sha1[3])) & 0xff) << 0));
 
3560
 
 
3561
  /* "bzrlib/_btree_serializer_pyx.pyx":496
 
3562
 *            | ((<unsigned int>(sha1[2]) & 0xff) << 8)
 
3563
 *            | ((<unsigned int>(sha1[3]) & 0xff) << 0))
 
3564
 *     return val             # <<<<<<<<<<<<<<
 
3565
 * 
 
3566
 * 
 
3567
 */
 
3568
  __pyx_r = __pyx_v_val;
 
3569
  goto __pyx_L0;
 
3570
 
 
3571
  __pyx_r = 0;
 
3572
  __pyx_L0:;
 
3573
  __Pyx_RefNannyFinishContext();
 
3574
  return __pyx_r;
 
3575
}
 
3576
 
 
3577
/* "bzrlib/_btree_serializer_pyx.pyx":499
 
3578
 * 
 
3579
 * 
 
3580
 * cdef _format_record(gc_chk_sha1_record *record):             # <<<<<<<<<<<<<<
 
3581
 *     # This is inefficient to go from a logical state back to a
 
3582
 *     # string, but it makes things work a bit better internally for now.
 
3583
 */
 
3584
 
 
3585
static  PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__format_record(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record) {
 
3586
  PyObject *__pyx_v_block_offset_str;
 
3587
  PyObject *__pyx_v_value;
 
3588
  PyObject *__pyx_r = NULL;
 
3589
  PyObject *__pyx_t_1 = NULL;
 
3590
  PyObject *__pyx_t_2 = NULL;
 
3591
  int __pyx_t_3;
 
3592
  __Pyx_RefNannySetupContext("_format_record");
 
3593
  __pyx_v_block_offset_str = Py_None; __Pyx_INCREF(Py_None);
 
3594
  __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);
 
3595
 
 
3596
  /* "bzrlib/_btree_serializer_pyx.pyx":502
 
3597
 *     # This is inefficient to go from a logical state back to a
 
3598
 *     # string, but it makes things work a bit better internally for now.
 
3599
 *     if record.block_offset >= 0xFFFFFFFF:             # <<<<<<<<<<<<<<
 
3600
 *         # %llu is what we really want, but unfortunately it was only added
 
3601
 *         # in python 2.7... :(
 
3602
 */
 
3603
  __pyx_t_1 = PyLong_FromLongLong(__pyx_v_record->block_offset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3604
  __Pyx_GOTREF(__pyx_t_1);
 
3605
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_4294967295, Py_GE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3606
  __Pyx_GOTREF(__pyx_t_2);
 
3607
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
3608
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3609
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
3610
  if (__pyx_t_3) {
 
3611
 
 
3612
    /* "bzrlib/_btree_serializer_pyx.pyx":505
 
3613
 *         # %llu is what we really want, but unfortunately it was only added
 
3614
 *         # in python 2.7... :(
 
3615
 *         block_offset_str = str(record.block_offset)             # <<<<<<<<<<<<<<
 
3616
 *         value = PyString_FromFormat('%s %u %u %u',
 
3617
 *                                 PyString_AS_STRING(block_offset_str),
 
3618
 */
 
3619
    __pyx_t_2 = PyLong_FromLongLong(__pyx_v_record->block_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3620
    __Pyx_GOTREF(__pyx_t_2);
 
3621
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3622
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
3623
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
 
3624
    __Pyx_GIVEREF(__pyx_t_2);
 
3625
    __pyx_t_2 = 0;
 
3626
    __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3627
    __Pyx_GOTREF(__pyx_t_2);
 
3628
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
3629
    __Pyx_DECREF(__pyx_v_block_offset_str);
 
3630
    __pyx_v_block_offset_str = __pyx_t_2;
 
3631
    __pyx_t_2 = 0;
 
3632
 
 
3633
    /* "bzrlib/_btree_serializer_pyx.pyx":509
 
3634
 *                                 PyString_AS_STRING(block_offset_str),
 
3635
 *                                 record.block_length,
 
3636
 *                                 record.record_start, record.record_end)             # <<<<<<<<<<<<<<
 
3637
 *     else:
 
3638
 *         value = PyString_FromFormat('%lu %u %u %u',
 
3639
 */
 
3640
    __pyx_t_2 = PyString_FromFormat(__pyx_k_24, PyString_AS_STRING(__pyx_v_block_offset_str), __pyx_v_record->block_length, __pyx_v_record->record_start, __pyx_v_record->record_end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3641
    __Pyx_GOTREF(__pyx_t_2);
 
3642
    __Pyx_DECREF(__pyx_v_value);
 
3643
    __pyx_v_value = __pyx_t_2;
 
3644
    __pyx_t_2 = 0;
 
3645
    goto __pyx_L3;
 
3646
  }
 
3647
  /*else*/ {
 
3648
 
 
3649
    /* "bzrlib/_btree_serializer_pyx.pyx":514
 
3650
 *                                     <unsigned long>record.block_offset,
 
3651
 *                                     record.block_length,
 
3652
 *                                     record.record_start, record.record_end)             # <<<<<<<<<<<<<<
 
3653
 *     return value
 
3654
 * 
 
3655
 */
 
3656
    __pyx_t_2 = PyString_FromFormat(__pyx_k_25, ((unsigned long)__pyx_v_record->block_offset), __pyx_v_record->block_length, __pyx_v_record->record_start, __pyx_v_record->record_end); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3657
    __Pyx_GOTREF(__pyx_t_2);
 
3658
    __Pyx_DECREF(__pyx_v_value);
 
3659
    __pyx_v_value = __pyx_t_2;
 
3660
    __pyx_t_2 = 0;
 
3661
  }
 
3662
  __pyx_L3:;
 
3663
 
 
3664
  /* "bzrlib/_btree_serializer_pyx.pyx":515
 
3665
 *                                     record.block_length,
 
3666
 *                                     record.record_start, record.record_end)
 
3667
 *     return value             # <<<<<<<<<<<<<<
 
3668
 * 
 
3669
 * 
 
3670
 */
 
3671
  __Pyx_XDECREF(__pyx_r);
 
3672
  __Pyx_INCREF(__pyx_v_value);
 
3673
  __pyx_r = __pyx_v_value;
 
3674
  goto __pyx_L0;
 
3675
 
 
3676
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
3677
  goto __pyx_L0;
 
3678
  __pyx_L1_error:;
 
3679
  __Pyx_XDECREF(__pyx_t_1);
 
3680
  __Pyx_XDECREF(__pyx_t_2);
 
3681
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._format_record");
 
3682
  __pyx_r = 0;
 
3683
  __pyx_L0:;
 
3684
  __Pyx_DECREF(__pyx_v_block_offset_str);
 
3685
  __Pyx_DECREF(__pyx_v_value);
 
3686
  __Pyx_XGIVEREF(__pyx_r);
 
3687
  __Pyx_RefNannyFinishContext();
 
3688
  return __pyx_r;
 
3689
}
 
3690
 
 
3691
/* "bzrlib/_btree_serializer_pyx.pyx":536
 
3692
 *     cdef unsigned char offsets[257]
 
3693
 * 
 
3694
 *     def __sizeof__(self):             # <<<<<<<<<<<<<<
 
3695
 *         # :( Why doesn't Pyrex let me do a simple sizeof(GCCHKSHA1LeafNode)
 
3696
 *         # like Cython? Explicitly enumerating everything here seems to leave my
 
3697
 */
 
3698
 
 
3699
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___sizeof__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
 
3700
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___sizeof__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
 
3701
  PyObject *__pyx_r = NULL;
 
3702
  PyObject *__pyx_t_1 = NULL;
 
3703
  __Pyx_RefNannySetupContext("__sizeof__");
 
3704
 
 
3705
  /* "bzrlib/_btree_serializer_pyx.pyx":546
 
3706
 *         # return (sizeof(GCCHKSHA1LeafNode)
 
3707
 *         #     + sizeof(gc_chk_sha1_record)*self.num_records)
 
3708
 *         return (sizeof(PyObject) + sizeof(void*) + sizeof(int)             # <<<<<<<<<<<<<<
 
3709
 *             + sizeof(gc_chk_sha1_record*) + sizeof(PyObject *)
 
3710
 *             + sizeof(gc_chk_sha1_record*) + sizeof(char)
 
3711
 */
 
3712
  __Pyx_XDECREF(__pyx_r);
 
3713
 
 
3714
  /* "bzrlib/_btree_serializer_pyx.pyx":550
 
3715
 *             + sizeof(gc_chk_sha1_record*) + sizeof(char)
 
3716
 *             + sizeof(unsigned char)*257
 
3717
 *             + sizeof(gc_chk_sha1_record)*self.num_records)             # <<<<<<<<<<<<<<
 
3718
 * 
 
3719
 *     def __dealloc__(self):
 
3720
 */
 
3721
  __pyx_t_1 = __Pyx_PyInt_FromSize_t((((((((((sizeof(PyObject)) + (sizeof(void *))) + (sizeof(int))) + (sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *))) + (sizeof(PyObject *))) + (sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *))) + (sizeof(char))) + ((sizeof(unsigned char)) * 257)) + ((sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record)) * ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3722
  __Pyx_GOTREF(__pyx_t_1);
 
3723
  __pyx_r = __pyx_t_1;
 
3724
  __pyx_t_1 = 0;
 
3725
  goto __pyx_L0;
 
3726
 
 
3727
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
3728
  goto __pyx_L0;
 
3729
  __pyx_L1_error:;
 
3730
  __Pyx_XDECREF(__pyx_t_1);
 
3731
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__sizeof__");
 
3732
  __pyx_r = NULL;
 
3733
  __pyx_L0:;
 
3734
  __Pyx_XGIVEREF(__pyx_r);
 
3735
  __Pyx_RefNannyFinishContext();
 
3736
  return __pyx_r;
 
3737
}
 
3738
 
 
3739
/* "bzrlib/_btree_serializer_pyx.pyx":552
 
3740
 *             + sizeof(gc_chk_sha1_record)*self.num_records)
 
3741
 * 
 
3742
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 
3743
 *         if self.records != NULL:
 
3744
 *             PyMem_Free(self.records)
 
3745
 */
 
3746
 
 
3747
static void __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_1__dealloc__(PyObject *__pyx_v_self); /*proto*/
 
3748
static void __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_1__dealloc__(PyObject *__pyx_v_self) {
 
3749
  int __pyx_t_1;
 
3750
  __Pyx_RefNannySetupContext("__dealloc__");
 
3751
 
 
3752
  /* "bzrlib/_btree_serializer_pyx.pyx":553
 
3753
 * 
 
3754
 *     def __dealloc__(self):
 
3755
 *         if self.records != NULL:             # <<<<<<<<<<<<<<
 
3756
 *             PyMem_Free(self.records)
 
3757
 *             self.records = NULL
 
3758
 */
 
3759
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records != NULL);
 
3760
  if (__pyx_t_1) {
 
3761
 
 
3762
    /* "bzrlib/_btree_serializer_pyx.pyx":554
 
3763
 *     def __dealloc__(self):
 
3764
 *         if self.records != NULL:
 
3765
 *             PyMem_Free(self.records)             # <<<<<<<<<<<<<<
 
3766
 *             self.records = NULL
 
3767
 * 
 
3768
 */
 
3769
    PyMem_Free(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records);
 
3770
 
 
3771
    /* "bzrlib/_btree_serializer_pyx.pyx":555
 
3772
 *         if self.records != NULL:
 
3773
 *             PyMem_Free(self.records)
 
3774
 *             self.records = NULL             # <<<<<<<<<<<<<<
 
3775
 * 
 
3776
 *     def __init__(self, bytes):
 
3777
 */
 
3778
    ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records = NULL;
 
3779
    goto __pyx_L5;
 
3780
  }
 
3781
  __pyx_L5:;
 
3782
 
 
3783
  __Pyx_RefNannyFinishContext();
 
3784
}
 
3785
 
 
3786
/* "bzrlib/_btree_serializer_pyx.pyx":557
 
3787
 *             self.records = NULL
 
3788
 * 
 
3789
 *     def __init__(self, bytes):             # <<<<<<<<<<<<<<
 
3790
 *         self._parse_bytes(bytes)
 
3791
 *         self.last_key = None
 
3792
 */
 
3793
 
 
3794
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_2__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
3795
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_2__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
3796
  PyObject *__pyx_v_bytes = 0;
 
3797
  int __pyx_r;
 
3798
  PyObject *__pyx_t_1 = NULL;
 
3799
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__bytes,0};
 
3800
  __Pyx_RefNannySetupContext("__init__");
 
3801
  if (unlikely(__pyx_kwds)) {
 
3802
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
 
3803
    PyObject* values[1] = {0};
 
3804
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
3805
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
 
3806
      case  0: break;
 
3807
      default: goto __pyx_L5_argtuple_error;
 
3808
    }
 
3809
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
3810
      case  0:
 
3811
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bytes);
 
3812
      if (likely(values[0])) kw_args--;
 
3813
      else goto __pyx_L5_argtuple_error;
 
3814
    }
 
3815
    if (unlikely(kw_args > 0)) {
 
3816
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
3817
    }
 
3818
    __pyx_v_bytes = values[0];
 
3819
  } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
 
3820
    goto __pyx_L5_argtuple_error;
 
3821
  } else {
 
3822
    __pyx_v_bytes = PyTuple_GET_ITEM(__pyx_args, 0);
 
3823
  }
 
3824
  goto __pyx_L4_argument_unpacking_done;
 
3825
  __pyx_L5_argtuple_error:;
 
3826
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
3827
  __pyx_L3_error:;
 
3828
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__init__");
 
3829
  __Pyx_RefNannyFinishContext();
 
3830
  return -1;
 
3831
  __pyx_L4_argument_unpacking_done:;
 
3832
 
 
3833
  /* "bzrlib/_btree_serializer_pyx.pyx":558
 
3834
 * 
 
3835
 *     def __init__(self, bytes):
 
3836
 *         self._parse_bytes(bytes)             # <<<<<<<<<<<<<<
 
3837
 *         self.last_key = None
 
3838
 *         self.last_record = NULL
 
3839
 */
 
3840
  __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_parse_bytes(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self), __pyx_v_bytes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3841
  __Pyx_GOTREF(__pyx_t_1);
 
3842
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
3843
 
 
3844
  /* "bzrlib/_btree_serializer_pyx.pyx":559
 
3845
 *     def __init__(self, bytes):
 
3846
 *         self._parse_bytes(bytes)
 
3847
 *         self.last_key = None             # <<<<<<<<<<<<<<
 
3848
 *         self.last_record = NULL
 
3849
 * 
 
3850
 */
 
3851
  __Pyx_INCREF(Py_None);
 
3852
  __Pyx_GIVEREF(Py_None);
 
3853
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
3854
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
3855
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key = Py_None;
 
3856
 
 
3857
  /* "bzrlib/_btree_serializer_pyx.pyx":560
 
3858
 *         self._parse_bytes(bytes)
 
3859
 *         self.last_key = None
 
3860
 *         self.last_record = NULL             # <<<<<<<<<<<<<<
 
3861
 * 
 
3862
 *     property min_key:
 
3863
 */
 
3864
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record = NULL;
 
3865
 
 
3866
  __pyx_r = 0;
 
3867
  goto __pyx_L0;
 
3868
  __pyx_L1_error:;
 
3869
  __Pyx_XDECREF(__pyx_t_1);
 
3870
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__init__");
 
3871
  __pyx_r = -1;
 
3872
  __pyx_L0:;
 
3873
  __Pyx_RefNannyFinishContext();
 
3874
  return __pyx_r;
 
3875
}
 
3876
 
 
3877
/* "bzrlib/_btree_serializer_pyx.pyx":563
 
3878
 * 
 
3879
 *     property min_key:
 
3880
 *         def __get__(self):             # <<<<<<<<<<<<<<
 
3881
 *             if self.num_records > 0:
 
3882
 *                 return _sha1_to_key(self.records[0].sha1)
 
3883
 */
 
3884
 
 
3885
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7min_key___get__(PyObject *__pyx_v_self); /*proto*/
 
3886
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7min_key___get__(PyObject *__pyx_v_self) {
 
3887
  PyObject *__pyx_r = NULL;
 
3888
  int __pyx_t_1;
 
3889
  PyObject *__pyx_t_2 = NULL;
 
3890
  __Pyx_RefNannySetupContext("__get__");
 
3891
 
 
3892
  /* "bzrlib/_btree_serializer_pyx.pyx":564
 
3893
 *     property min_key:
 
3894
 *         def __get__(self):
 
3895
 *             if self.num_records > 0:             # <<<<<<<<<<<<<<
 
3896
 *                 return _sha1_to_key(self.records[0].sha1)
 
3897
 *             return None
 
3898
 */
 
3899
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records > 0);
 
3900
  if (__pyx_t_1) {
 
3901
 
 
3902
    /* "bzrlib/_btree_serializer_pyx.pyx":565
 
3903
 *         def __get__(self):
 
3904
 *             if self.num_records > 0:
 
3905
 *                 return _sha1_to_key(self.records[0].sha1)             # <<<<<<<<<<<<<<
 
3906
 *             return None
 
3907
 * 
 
3908
 */
 
3909
    __Pyx_XDECREF(__pyx_r);
 
3910
    __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[0]).sha1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3911
    __Pyx_GOTREF(__pyx_t_2);
 
3912
    __pyx_r = __pyx_t_2;
 
3913
    __pyx_t_2 = 0;
 
3914
    goto __pyx_L0;
 
3915
    goto __pyx_L5;
 
3916
  }
 
3917
  __pyx_L5:;
 
3918
 
 
3919
  /* "bzrlib/_btree_serializer_pyx.pyx":566
 
3920
 *             if self.num_records > 0:
 
3921
 *                 return _sha1_to_key(self.records[0].sha1)
 
3922
 *             return None             # <<<<<<<<<<<<<<
 
3923
 * 
 
3924
 *     property max_key:
 
3925
 */
 
3926
  __Pyx_XDECREF(__pyx_r);
 
3927
  __Pyx_INCREF(Py_None);
 
3928
  __pyx_r = Py_None;
 
3929
  goto __pyx_L0;
 
3930
 
 
3931
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
3932
  goto __pyx_L0;
 
3933
  __pyx_L1_error:;
 
3934
  __Pyx_XDECREF(__pyx_t_2);
 
3935
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.min_key.__get__");
 
3936
  __pyx_r = NULL;
 
3937
  __pyx_L0:;
 
3938
  __Pyx_XGIVEREF(__pyx_r);
 
3939
  __Pyx_RefNannyFinishContext();
 
3940
  return __pyx_r;
 
3941
}
 
3942
 
 
3943
/* "bzrlib/_btree_serializer_pyx.pyx":569
 
3944
 * 
 
3945
 *     property max_key:
 
3946
 *         def __get__(self):             # <<<<<<<<<<<<<<
 
3947
 *             if self.num_records > 0:
 
3948
 *                 return _sha1_to_key(self.records[self.num_records-1].sha1)
 
3949
 */
 
3950
 
 
3951
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7max_key___get__(PyObject *__pyx_v_self); /*proto*/
 
3952
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7max_key___get__(PyObject *__pyx_v_self) {
 
3953
  PyObject *__pyx_r = NULL;
 
3954
  int __pyx_t_1;
 
3955
  PyObject *__pyx_t_2 = NULL;
 
3956
  __Pyx_RefNannySetupContext("__get__");
 
3957
 
 
3958
  /* "bzrlib/_btree_serializer_pyx.pyx":570
 
3959
 *     property max_key:
 
3960
 *         def __get__(self):
 
3961
 *             if self.num_records > 0:             # <<<<<<<<<<<<<<
 
3962
 *                 return _sha1_to_key(self.records[self.num_records-1].sha1)
 
3963
 *             return None
 
3964
 */
 
3965
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records > 0);
 
3966
  if (__pyx_t_1) {
 
3967
 
 
3968
    /* "bzrlib/_btree_serializer_pyx.pyx":571
 
3969
 *         def __get__(self):
 
3970
 *             if self.num_records > 0:
 
3971
 *                 return _sha1_to_key(self.records[self.num_records-1].sha1)             # <<<<<<<<<<<<<<
 
3972
 *             return None
 
3973
 * 
 
3974
 */
 
3975
    __Pyx_XDECREF(__pyx_r);
 
3976
    __pyx_t_2 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records - 1)]).sha1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
3977
    __Pyx_GOTREF(__pyx_t_2);
 
3978
    __pyx_r = __pyx_t_2;
 
3979
    __pyx_t_2 = 0;
 
3980
    goto __pyx_L0;
 
3981
    goto __pyx_L5;
 
3982
  }
 
3983
  __pyx_L5:;
 
3984
 
 
3985
  /* "bzrlib/_btree_serializer_pyx.pyx":572
 
3986
 *             if self.num_records > 0:
 
3987
 *                 return _sha1_to_key(self.records[self.num_records-1].sha1)
 
3988
 *             return None             # <<<<<<<<<<<<<<
 
3989
 * 
 
3990
 *     cdef StaticTuple _record_to_value_and_refs(self,
 
3991
 */
 
3992
  __Pyx_XDECREF(__pyx_r);
 
3993
  __Pyx_INCREF(Py_None);
 
3994
  __pyx_r = Py_None;
 
3995
  goto __pyx_L0;
 
3996
 
 
3997
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
3998
  goto __pyx_L0;
 
3999
  __pyx_L1_error:;
 
4000
  __Pyx_XDECREF(__pyx_t_2);
 
4001
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.max_key.__get__");
 
4002
  __pyx_r = NULL;
 
4003
  __pyx_L0:;
 
4004
  __Pyx_XGIVEREF(__pyx_r);
 
4005
  __Pyx_RefNannyFinishContext();
 
4006
  return __pyx_r;
 
4007
}
 
4008
 
 
4009
/* "bzrlib/_btree_serializer_pyx.pyx":574
 
4010
 *             return None
 
4011
 * 
 
4012
 *     cdef StaticTuple _record_to_value_and_refs(self,             # <<<<<<<<<<<<<<
 
4013
 *                                                gc_chk_sha1_record *record):
 
4014
 *         """Extract the refs and value part of this record."""
 
4015
 */
 
4016
 
 
4017
static  StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_value_and_refs(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record) {
 
4018
  StaticTuple *__pyx_v_value_and_refs;
 
4019
  StaticTuple *__pyx_v_empty;
 
4020
  PyObject *__pyx_v_value;
 
4021
  StaticTuple *__pyx_r = NULL;
 
4022
  PyObject *__pyx_t_1 = NULL;
 
4023
  __Pyx_RefNannySetupContext("_record_to_value_and_refs");
 
4024
  __pyx_v_value_and_refs = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4025
  __pyx_v_empty = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4026
  __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);
 
4027
 
 
4028
  /* "bzrlib/_btree_serializer_pyx.pyx":579
 
4029
 *         cdef StaticTuple value_and_refs
 
4030
 *         cdef StaticTuple empty
 
4031
 *         value_and_refs = StaticTuple_New(2)             # <<<<<<<<<<<<<<
 
4032
 *         value = _format_record(record)
 
4033
 *         Py_INCREF(value)
 
4034
 */
 
4035
  __pyx_t_1 = ((PyObject *)StaticTuple_New(2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4036
  __Pyx_GOTREF(__pyx_t_1);
 
4037
  __Pyx_DECREF(((PyObject *)__pyx_v_value_and_refs));
 
4038
  __pyx_v_value_and_refs = ((StaticTuple *)__pyx_t_1);
 
4039
  __pyx_t_1 = 0;
 
4040
 
 
4041
  /* "bzrlib/_btree_serializer_pyx.pyx":580
 
4042
 *         cdef StaticTuple empty
 
4043
 *         value_and_refs = StaticTuple_New(2)
 
4044
 *         value = _format_record(record)             # <<<<<<<<<<<<<<
 
4045
 *         Py_INCREF(value)
 
4046
 *         StaticTuple_SET_ITEM(value_and_refs, 0, value)
 
4047
 */
 
4048
  __pyx_t_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx__format_record(__pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4049
  __Pyx_GOTREF(__pyx_t_1);
 
4050
  __Pyx_DECREF(__pyx_v_value);
 
4051
  __pyx_v_value = __pyx_t_1;
 
4052
  __pyx_t_1 = 0;
 
4053
 
 
4054
  /* "bzrlib/_btree_serializer_pyx.pyx":581
 
4055
 *         value_and_refs = StaticTuple_New(2)
 
4056
 *         value = _format_record(record)
 
4057
 *         Py_INCREF(value)             # <<<<<<<<<<<<<<
 
4058
 *         StaticTuple_SET_ITEM(value_and_refs, 0, value)
 
4059
 *         # Always empty refs
 
4060
 */
 
4061
  Py_INCREF(__pyx_v_value);
 
4062
 
 
4063
  /* "bzrlib/_btree_serializer_pyx.pyx":582
 
4064
 *         value = _format_record(record)
 
4065
 *         Py_INCREF(value)
 
4066
 *         StaticTuple_SET_ITEM(value_and_refs, 0, value)             # <<<<<<<<<<<<<<
 
4067
 *         # Always empty refs
 
4068
 *         empty = StaticTuple_New(0)
 
4069
 */
 
4070
  StaticTuple_SET_ITEM(__pyx_v_value_and_refs, 0, __pyx_v_value);
 
4071
 
 
4072
  /* "bzrlib/_btree_serializer_pyx.pyx":584
 
4073
 *         StaticTuple_SET_ITEM(value_and_refs, 0, value)
 
4074
 *         # Always empty refs
 
4075
 *         empty = StaticTuple_New(0)             # <<<<<<<<<<<<<<
 
4076
 *         Py_INCREF(empty)
 
4077
 *         StaticTuple_SET_ITEM(value_and_refs, 1, empty)
 
4078
 */
 
4079
  __pyx_t_1 = ((PyObject *)StaticTuple_New(0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4080
  __Pyx_GOTREF(__pyx_t_1);
 
4081
  __Pyx_DECREF(((PyObject *)__pyx_v_empty));
 
4082
  __pyx_v_empty = ((StaticTuple *)__pyx_t_1);
 
4083
  __pyx_t_1 = 0;
 
4084
 
 
4085
  /* "bzrlib/_btree_serializer_pyx.pyx":585
 
4086
 *         # Always empty refs
 
4087
 *         empty = StaticTuple_New(0)
 
4088
 *         Py_INCREF(empty)             # <<<<<<<<<<<<<<
 
4089
 *         StaticTuple_SET_ITEM(value_and_refs, 1, empty)
 
4090
 *         return value_and_refs
 
4091
 */
 
4092
  Py_INCREF(((PyObject *)__pyx_v_empty));
 
4093
 
 
4094
  /* "bzrlib/_btree_serializer_pyx.pyx":586
 
4095
 *         empty = StaticTuple_New(0)
 
4096
 *         Py_INCREF(empty)
 
4097
 *         StaticTuple_SET_ITEM(value_and_refs, 1, empty)             # <<<<<<<<<<<<<<
 
4098
 *         return value_and_refs
 
4099
 * 
 
4100
 */
 
4101
  StaticTuple_SET_ITEM(__pyx_v_value_and_refs, 1, ((PyObject *)__pyx_v_empty));
 
4102
 
 
4103
  /* "bzrlib/_btree_serializer_pyx.pyx":587
 
4104
 *         Py_INCREF(empty)
 
4105
 *         StaticTuple_SET_ITEM(value_and_refs, 1, empty)
 
4106
 *         return value_and_refs             # <<<<<<<<<<<<<<
 
4107
 * 
 
4108
 *     cdef StaticTuple _record_to_item(self, gc_chk_sha1_record *record):
 
4109
 */
 
4110
  __Pyx_XDECREF(((PyObject *)__pyx_r));
 
4111
  __Pyx_INCREF(((PyObject *)__pyx_v_value_and_refs));
 
4112
  __pyx_r = __pyx_v_value_and_refs;
 
4113
  goto __pyx_L0;
 
4114
 
 
4115
  __pyx_r = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4116
  goto __pyx_L0;
 
4117
  __pyx_L1_error:;
 
4118
  __Pyx_XDECREF(__pyx_t_1);
 
4119
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._record_to_value_and_refs");
 
4120
  __pyx_r = 0;
 
4121
  __pyx_L0:;
 
4122
  __Pyx_DECREF((PyObject *)__pyx_v_value_and_refs);
 
4123
  __Pyx_DECREF((PyObject *)__pyx_v_empty);
 
4124
  __Pyx_DECREF(__pyx_v_value);
 
4125
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
 
4126
  __Pyx_RefNannyFinishContext();
 
4127
  return __pyx_r;
 
4128
}
 
4129
 
 
4130
/* "bzrlib/_btree_serializer_pyx.pyx":589
 
4131
 *         return value_and_refs
 
4132
 * 
 
4133
 *     cdef StaticTuple _record_to_item(self, gc_chk_sha1_record *record):             # <<<<<<<<<<<<<<
 
4134
 *         """Turn a given record back into a fully fledged item.
 
4135
 *         """
 
4136
 */
 
4137
 
 
4138
static  StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_item(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record) {
 
4139
  StaticTuple *__pyx_v_item;
 
4140
  StaticTuple *__pyx_v_key;
 
4141
  StaticTuple *__pyx_v_value_and_refs;
 
4142
  StaticTuple *__pyx_r = NULL;
 
4143
  PyObject *__pyx_t_1 = NULL;
 
4144
  __Pyx_RefNannySetupContext("_record_to_item");
 
4145
  __pyx_v_item = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4146
  __pyx_v_key = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4147
  __pyx_v_value_and_refs = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4148
 
 
4149
  /* "bzrlib/_btree_serializer_pyx.pyx":596
 
4150
 *         cdef StaticTuple value_and_refs
 
4151
 *         cdef object value
 
4152
 *         key = _sha1_to_key(record.sha1)             # <<<<<<<<<<<<<<
 
4153
 *         item = StaticTuple_New(2)
 
4154
 *         Py_INCREF(key)
 
4155
 */
 
4156
  __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(__pyx_v_record->sha1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4157
  __Pyx_GOTREF(__pyx_t_1);
 
4158
  __Pyx_DECREF(((PyObject *)__pyx_v_key));
 
4159
  __pyx_v_key = ((StaticTuple *)__pyx_t_1);
 
4160
  __pyx_t_1 = 0;
 
4161
 
 
4162
  /* "bzrlib/_btree_serializer_pyx.pyx":597
 
4163
 *         cdef object value
 
4164
 *         key = _sha1_to_key(record.sha1)
 
4165
 *         item = StaticTuple_New(2)             # <<<<<<<<<<<<<<
 
4166
 *         Py_INCREF(key)
 
4167
 *         StaticTuple_SET_ITEM(item, 0, key)
 
4168
 */
 
4169
  __pyx_t_1 = ((PyObject *)StaticTuple_New(2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4170
  __Pyx_GOTREF(__pyx_t_1);
 
4171
  __Pyx_DECREF(((PyObject *)__pyx_v_item));
 
4172
  __pyx_v_item = ((StaticTuple *)__pyx_t_1);
 
4173
  __pyx_t_1 = 0;
 
4174
 
 
4175
  /* "bzrlib/_btree_serializer_pyx.pyx":598
 
4176
 *         key = _sha1_to_key(record.sha1)
 
4177
 *         item = StaticTuple_New(2)
 
4178
 *         Py_INCREF(key)             # <<<<<<<<<<<<<<
 
4179
 *         StaticTuple_SET_ITEM(item, 0, key)
 
4180
 *         value_and_refs = self._record_to_value_and_refs(record)
 
4181
 */
 
4182
  Py_INCREF(((PyObject *)__pyx_v_key));
 
4183
 
 
4184
  /* "bzrlib/_btree_serializer_pyx.pyx":599
 
4185
 *         item = StaticTuple_New(2)
 
4186
 *         Py_INCREF(key)
 
4187
 *         StaticTuple_SET_ITEM(item, 0, key)             # <<<<<<<<<<<<<<
 
4188
 *         value_and_refs = self._record_to_value_and_refs(record)
 
4189
 *         Py_INCREF(value_and_refs)
 
4190
 */
 
4191
  StaticTuple_SET_ITEM(__pyx_v_item, 0, ((PyObject *)__pyx_v_key));
 
4192
 
 
4193
  /* "bzrlib/_btree_serializer_pyx.pyx":600
 
4194
 *         Py_INCREF(key)
 
4195
 *         StaticTuple_SET_ITEM(item, 0, key)
 
4196
 *         value_and_refs = self._record_to_value_and_refs(record)             # <<<<<<<<<<<<<<
 
4197
 *         Py_INCREF(value_and_refs)
 
4198
 *         StaticTuple_SET_ITEM(item, 1, value_and_refs)
 
4199
 */
 
4200
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_record_to_value_and_refs(__pyx_v_self, __pyx_v_record)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4201
  __Pyx_GOTREF(__pyx_t_1);
 
4202
  __Pyx_DECREF(((PyObject *)__pyx_v_value_and_refs));
 
4203
  __pyx_v_value_and_refs = ((StaticTuple *)__pyx_t_1);
 
4204
  __pyx_t_1 = 0;
 
4205
 
 
4206
  /* "bzrlib/_btree_serializer_pyx.pyx":601
 
4207
 *         StaticTuple_SET_ITEM(item, 0, key)
 
4208
 *         value_and_refs = self._record_to_value_and_refs(record)
 
4209
 *         Py_INCREF(value_and_refs)             # <<<<<<<<<<<<<<
 
4210
 *         StaticTuple_SET_ITEM(item, 1, value_and_refs)
 
4211
 *         return item
 
4212
 */
 
4213
  Py_INCREF(((PyObject *)__pyx_v_value_and_refs));
 
4214
 
 
4215
  /* "bzrlib/_btree_serializer_pyx.pyx":602
 
4216
 *         value_and_refs = self._record_to_value_and_refs(record)
 
4217
 *         Py_INCREF(value_and_refs)
 
4218
 *         StaticTuple_SET_ITEM(item, 1, value_and_refs)             # <<<<<<<<<<<<<<
 
4219
 *         return item
 
4220
 * 
 
4221
 */
 
4222
  StaticTuple_SET_ITEM(__pyx_v_item, 1, ((PyObject *)__pyx_v_value_and_refs));
 
4223
 
 
4224
  /* "bzrlib/_btree_serializer_pyx.pyx":603
 
4225
 *         Py_INCREF(value_and_refs)
 
4226
 *         StaticTuple_SET_ITEM(item, 1, value_and_refs)
 
4227
 *         return item             # <<<<<<<<<<<<<<
 
4228
 * 
 
4229
 *     cdef gc_chk_sha1_record* _lookup_record(self, char *sha1) except? NULL:
 
4230
 */
 
4231
  __Pyx_XDECREF(((PyObject *)__pyx_r));
 
4232
  __Pyx_INCREF(((PyObject *)__pyx_v_item));
 
4233
  __pyx_r = __pyx_v_item;
 
4234
  goto __pyx_L0;
 
4235
 
 
4236
  __pyx_r = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4237
  goto __pyx_L0;
 
4238
  __pyx_L1_error:;
 
4239
  __Pyx_XDECREF(__pyx_t_1);
 
4240
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._record_to_item");
 
4241
  __pyx_r = 0;
 
4242
  __pyx_L0:;
 
4243
  __Pyx_DECREF((PyObject *)__pyx_v_item);
 
4244
  __Pyx_DECREF((PyObject *)__pyx_v_key);
 
4245
  __Pyx_DECREF((PyObject *)__pyx_v_value_and_refs);
 
4246
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
 
4247
  __Pyx_RefNannyFinishContext();
 
4248
  return __pyx_r;
 
4249
}
 
4250
 
 
4251
/* "bzrlib/_btree_serializer_pyx.pyx":605
 
4252
 *         return item
 
4253
 * 
 
4254
 *     cdef gc_chk_sha1_record* _lookup_record(self, char *sha1) except? NULL:             # <<<<<<<<<<<<<<
 
4255
 *         """Find a gc_chk_sha1_record that matches the sha1 supplied."""
 
4256
 *         cdef int lo, hi, mid, the_cmp
 
4257
 */
 
4258
 
 
4259
static  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__lookup_record(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self, char *__pyx_v_sha1) {
 
4260
  int __pyx_v_lo;
 
4261
  int __pyx_v_hi;
 
4262
  int __pyx_v_mid;
 
4263
  int __pyx_v_the_cmp;
 
4264
  int __pyx_v_offset;
 
4265
  long __pyx_v_local_n_cmp;
 
4266
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_r;
 
4267
  int __pyx_t_1;
 
4268
  int __pyx_t_2;
 
4269
  __Pyx_RefNannySetupContext("_lookup_record");
 
4270
 
 
4271
  /* "bzrlib/_btree_serializer_pyx.pyx":619
 
4272
 *         # the offset array dropped us from 23us to 20us and 156 comparisions
 
4273
 *         # (1.3/key)
 
4274
 *         offset = self._offset_for_sha1(sha1)             # <<<<<<<<<<<<<<
 
4275
 *         lo = self.offsets[offset]
 
4276
 *         hi = self.offsets[offset+1]
 
4277
 */
 
4278
  __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_offset_for_sha1(__pyx_v_self, __pyx_v_sha1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4279
  __pyx_v_offset = __pyx_t_1;
 
4280
 
 
4281
  /* "bzrlib/_btree_serializer_pyx.pyx":620
 
4282
 *         # (1.3/key)
 
4283
 *         offset = self._offset_for_sha1(sha1)
 
4284
 *         lo = self.offsets[offset]             # <<<<<<<<<<<<<<
 
4285
 *         hi = self.offsets[offset+1]
 
4286
 *         if hi == 255:
 
4287
 */
 
4288
  __pyx_v_lo = (__pyx_v_self->offsets[__pyx_v_offset]);
 
4289
 
 
4290
  /* "bzrlib/_btree_serializer_pyx.pyx":621
 
4291
 *         offset = self._offset_for_sha1(sha1)
 
4292
 *         lo = self.offsets[offset]
 
4293
 *         hi = self.offsets[offset+1]             # <<<<<<<<<<<<<<
 
4294
 *         if hi == 255:
 
4295
 *             # if hi == 255 that means we potentially ran off the end of the
 
4296
 */
 
4297
  __pyx_v_hi = (__pyx_v_self->offsets[(__pyx_v_offset + 1)]);
 
4298
 
 
4299
  /* "bzrlib/_btree_serializer_pyx.pyx":622
 
4300
 *         lo = self.offsets[offset]
 
4301
 *         hi = self.offsets[offset+1]
 
4302
 *         if hi == 255:             # <<<<<<<<<<<<<<
 
4303
 *             # if hi == 255 that means we potentially ran off the end of the
 
4304
 *             # list, so push it up to num_records
 
4305
 */
 
4306
  __pyx_t_2 = (__pyx_v_hi == 255);
 
4307
  if (__pyx_t_2) {
 
4308
 
 
4309
    /* "bzrlib/_btree_serializer_pyx.pyx":627
 
4310
 *             # note that if 'lo' == 255, that is ok, because we can start
 
4311
 *             # searching from that part of the list.
 
4312
 *             hi = self.num_records             # <<<<<<<<<<<<<<
 
4313
 *         local_n_cmp = 0
 
4314
 *         while lo < hi:
 
4315
 */
 
4316
    __pyx_v_hi = __pyx_v_self->num_records;
 
4317
    goto __pyx_L3;
 
4318
  }
 
4319
  __pyx_L3:;
 
4320
 
 
4321
  /* "bzrlib/_btree_serializer_pyx.pyx":628
 
4322
 *             # searching from that part of the list.
 
4323
 *             hi = self.num_records
 
4324
 *         local_n_cmp = 0             # <<<<<<<<<<<<<<
 
4325
 *         while lo < hi:
 
4326
 *             mid = (lo + hi) / 2
 
4327
 */
 
4328
  __pyx_v_local_n_cmp = 0;
 
4329
 
 
4330
  /* "bzrlib/_btree_serializer_pyx.pyx":629
 
4331
 *             hi = self.num_records
 
4332
 *         local_n_cmp = 0
 
4333
 *         while lo < hi:             # <<<<<<<<<<<<<<
 
4334
 *             mid = (lo + hi) / 2
 
4335
 *             the_cmp = memcmp(self.records[mid].sha1, sha1, 20)
 
4336
 */
 
4337
  while (1) {
 
4338
    __pyx_t_2 = (__pyx_v_lo < __pyx_v_hi);
 
4339
    if (!__pyx_t_2) break;
 
4340
 
 
4341
    /* "bzrlib/_btree_serializer_pyx.pyx":630
 
4342
 *         local_n_cmp = 0
 
4343
 *         while lo < hi:
 
4344
 *             mid = (lo + hi) / 2             # <<<<<<<<<<<<<<
 
4345
 *             the_cmp = memcmp(self.records[mid].sha1, sha1, 20)
 
4346
 *             if the_cmp == 0:
 
4347
 */
 
4348
    __pyx_v_mid = __Pyx_div_long((__pyx_v_lo + __pyx_v_hi), 2);
 
4349
 
 
4350
    /* "bzrlib/_btree_serializer_pyx.pyx":631
 
4351
 *         while lo < hi:
 
4352
 *             mid = (lo + hi) / 2
 
4353
 *             the_cmp = memcmp(self.records[mid].sha1, sha1, 20)             # <<<<<<<<<<<<<<
 
4354
 *             if the_cmp == 0:
 
4355
 *                 return &self.records[mid]
 
4356
 */
 
4357
    __pyx_v_the_cmp = memcmp((__pyx_v_self->records[__pyx_v_mid]).sha1, __pyx_v_sha1, 20);
 
4358
 
 
4359
    /* "bzrlib/_btree_serializer_pyx.pyx":632
 
4360
 *             mid = (lo + hi) / 2
 
4361
 *             the_cmp = memcmp(self.records[mid].sha1, sha1, 20)
 
4362
 *             if the_cmp == 0:             # <<<<<<<<<<<<<<
 
4363
 *                 return &self.records[mid]
 
4364
 *             elif the_cmp < 0:
 
4365
 */
 
4366
    __pyx_t_2 = (__pyx_v_the_cmp == 0);
 
4367
    if (__pyx_t_2) {
 
4368
 
 
4369
      /* "bzrlib/_btree_serializer_pyx.pyx":633
 
4370
 *             the_cmp = memcmp(self.records[mid].sha1, sha1, 20)
 
4371
 *             if the_cmp == 0:
 
4372
 *                 return &self.records[mid]             # <<<<<<<<<<<<<<
 
4373
 *             elif the_cmp < 0:
 
4374
 *                 lo = mid + 1
 
4375
 */
 
4376
      __pyx_r = (&(__pyx_v_self->records[__pyx_v_mid]));
 
4377
      goto __pyx_L0;
 
4378
      goto __pyx_L6;
 
4379
    }
 
4380
 
 
4381
    /* "bzrlib/_btree_serializer_pyx.pyx":634
 
4382
 *             if the_cmp == 0:
 
4383
 *                 return &self.records[mid]
 
4384
 *             elif the_cmp < 0:             # <<<<<<<<<<<<<<
 
4385
 *                 lo = mid + 1
 
4386
 *             else:
 
4387
 */
 
4388
    __pyx_t_2 = (__pyx_v_the_cmp < 0);
 
4389
    if (__pyx_t_2) {
 
4390
 
 
4391
      /* "bzrlib/_btree_serializer_pyx.pyx":635
 
4392
 *                 return &self.records[mid]
 
4393
 *             elif the_cmp < 0:
 
4394
 *                 lo = mid + 1             # <<<<<<<<<<<<<<
 
4395
 *             else:
 
4396
 *                 hi = mid
 
4397
 */
 
4398
      __pyx_v_lo = (__pyx_v_mid + 1);
 
4399
      goto __pyx_L6;
 
4400
    }
 
4401
    /*else*/ {
 
4402
 
 
4403
      /* "bzrlib/_btree_serializer_pyx.pyx":637
 
4404
 *                 lo = mid + 1
 
4405
 *             else:
 
4406
 *                 hi = mid             # <<<<<<<<<<<<<<
 
4407
 *         return NULL
 
4408
 * 
 
4409
 */
 
4410
      __pyx_v_hi = __pyx_v_mid;
 
4411
    }
 
4412
    __pyx_L6:;
 
4413
  }
 
4414
 
 
4415
  /* "bzrlib/_btree_serializer_pyx.pyx":638
 
4416
 *             else:
 
4417
 *                 hi = mid
 
4418
 *         return NULL             # <<<<<<<<<<<<<<
 
4419
 * 
 
4420
 *     def __contains__(self, key):
 
4421
 */
 
4422
  __pyx_r = NULL;
 
4423
  goto __pyx_L0;
 
4424
 
 
4425
  __pyx_r = 0;
 
4426
  goto __pyx_L0;
 
4427
  __pyx_L1_error:;
 
4428
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._lookup_record");
 
4429
  __pyx_r = NULL;
 
4430
  __pyx_L0:;
 
4431
  __Pyx_RefNannyFinishContext();
 
4432
  return __pyx_r;
 
4433
}
 
4434
 
 
4435
/* "bzrlib/_btree_serializer_pyx.pyx":640
 
4436
 *         return NULL
 
4437
 * 
 
4438
 *     def __contains__(self, key):             # <<<<<<<<<<<<<<
 
4439
 *         cdef char sha1[20]
 
4440
 *         cdef gc_chk_sha1_record *record
 
4441
 */
 
4442
 
 
4443
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_3__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
 
4444
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_3__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
 
4445
  char __pyx_v_sha1[20];
 
4446
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record;
 
4447
  int __pyx_r;
 
4448
  int __pyx_t_1;
 
4449
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_t_2;
 
4450
  int __pyx_t_3;
 
4451
  __Pyx_RefNannySetupContext("__contains__");
 
4452
 
 
4453
  /* "bzrlib/_btree_serializer_pyx.pyx":643
 
4454
 *         cdef char sha1[20]
 
4455
 *         cdef gc_chk_sha1_record *record
 
4456
 *         if _key_to_sha1(key, sha1):             # <<<<<<<<<<<<<<
 
4457
 *             # If it isn't a sha1 key, then it won't be in this leaf node
 
4458
 *             record = self._lookup_record(sha1)
 
4459
 */
 
4460
  __pyx_t_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(__pyx_v_key, __pyx_v_sha1);
 
4461
  if (__pyx_t_1) {
 
4462
 
 
4463
    /* "bzrlib/_btree_serializer_pyx.pyx":645
 
4464
 *         if _key_to_sha1(key, sha1):
 
4465
 *             # If it isn't a sha1 key, then it won't be in this leaf node
 
4466
 *             record = self._lookup_record(sha1)             # <<<<<<<<<<<<<<
 
4467
 *             if record != NULL:
 
4468
 *                 self.last_key = key
 
4469
 */
 
4470
    __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_lookup_record(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self), __pyx_v_sha1); if (unlikely(__pyx_t_2 == NULL && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4471
    __pyx_v_record = __pyx_t_2;
 
4472
 
 
4473
    /* "bzrlib/_btree_serializer_pyx.pyx":646
 
4474
 *             # If it isn't a sha1 key, then it won't be in this leaf node
 
4475
 *             record = self._lookup_record(sha1)
 
4476
 *             if record != NULL:             # <<<<<<<<<<<<<<
 
4477
 *                 self.last_key = key
 
4478
 *                 self.last_record = record
 
4479
 */
 
4480
    __pyx_t_3 = (__pyx_v_record != NULL);
 
4481
    if (__pyx_t_3) {
 
4482
 
 
4483
      /* "bzrlib/_btree_serializer_pyx.pyx":647
 
4484
 *             record = self._lookup_record(sha1)
 
4485
 *             if record != NULL:
 
4486
 *                 self.last_key = key             # <<<<<<<<<<<<<<
 
4487
 *                 self.last_record = record
 
4488
 *                 return True
 
4489
 */
 
4490
      __Pyx_INCREF(__pyx_v_key);
 
4491
      __Pyx_GIVEREF(__pyx_v_key);
 
4492
      __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
4493
      __Pyx_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
4494
      ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key = __pyx_v_key;
 
4495
 
 
4496
      /* "bzrlib/_btree_serializer_pyx.pyx":648
 
4497
 *             if record != NULL:
 
4498
 *                 self.last_key = key
 
4499
 *                 self.last_record = record             # <<<<<<<<<<<<<<
 
4500
 *                 return True
 
4501
 *         return False
 
4502
 */
 
4503
      ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record = __pyx_v_record;
 
4504
 
 
4505
      /* "bzrlib/_btree_serializer_pyx.pyx":649
 
4506
 *                 self.last_key = key
 
4507
 *                 self.last_record = record
 
4508
 *                 return True             # <<<<<<<<<<<<<<
 
4509
 *         return False
 
4510
 * 
 
4511
 */
 
4512
      __pyx_r = 1;
 
4513
      goto __pyx_L0;
 
4514
      goto __pyx_L6;
 
4515
    }
 
4516
    __pyx_L6:;
 
4517
    goto __pyx_L5;
 
4518
  }
 
4519
  __pyx_L5:;
 
4520
 
 
4521
  /* "bzrlib/_btree_serializer_pyx.pyx":650
 
4522
 *                 self.last_record = record
 
4523
 *                 return True
 
4524
 *         return False             # <<<<<<<<<<<<<<
 
4525
 * 
 
4526
 *     def __getitem__(self, key):
 
4527
 */
 
4528
  __pyx_r = 0;
 
4529
  goto __pyx_L0;
 
4530
 
 
4531
  __pyx_r = 0;
 
4532
  goto __pyx_L0;
 
4533
  __pyx_L1_error:;
 
4534
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__contains__");
 
4535
  __pyx_r = -1;
 
4536
  __pyx_L0:;
 
4537
  __Pyx_RefNannyFinishContext();
 
4538
  return __pyx_r;
 
4539
}
 
4540
 
 
4541
/* "bzrlib/_btree_serializer_pyx.pyx":652
 
4542
 *         return False
 
4543
 * 
 
4544
 *     def __getitem__(self, key):             # <<<<<<<<<<<<<<
 
4545
 *         cdef char sha1[20]
 
4546
 *         cdef gc_chk_sha1_record *record
 
4547
 */
 
4548
 
 
4549
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_4__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
 
4550
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_4__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
 
4551
  char __pyx_v_sha1[20];
 
4552
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record;
 
4553
  PyObject *__pyx_r = NULL;
 
4554
  int __pyx_t_1;
 
4555
  int __pyx_t_2;
 
4556
  int __pyx_t_3;
 
4557
  int __pyx_t_4;
 
4558
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_t_5;
 
4559
  PyObject *__pyx_t_6 = NULL;
 
4560
  PyObject *__pyx_t_7 = NULL;
 
4561
  __Pyx_RefNannySetupContext("__getitem__");
 
4562
 
 
4563
  /* "bzrlib/_btree_serializer_pyx.pyx":655
 
4564
 *         cdef char sha1[20]
 
4565
 *         cdef gc_chk_sha1_record *record
 
4566
 *         record = NULL             # <<<<<<<<<<<<<<
 
4567
 *         if self.last_record != NULL and key is self.last_key:
 
4568
 *             record = self.last_record
 
4569
 */
 
4570
  __pyx_v_record = NULL;
 
4571
 
 
4572
  /* "bzrlib/_btree_serializer_pyx.pyx":656
 
4573
 *         cdef gc_chk_sha1_record *record
 
4574
 *         record = NULL
 
4575
 *         if self.last_record != NULL and key is self.last_key:             # <<<<<<<<<<<<<<
 
4576
 *             record = self.last_record
 
4577
 *         elif _key_to_sha1(key, sha1):
 
4578
 */
 
4579
  __pyx_t_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record != NULL);
 
4580
  if (__pyx_t_1) {
 
4581
    __pyx_t_2 = (__pyx_v_key == ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
4582
    __pyx_t_3 = __pyx_t_2;
 
4583
  } else {
 
4584
    __pyx_t_3 = __pyx_t_1;
 
4585
  }
 
4586
  if (__pyx_t_3) {
 
4587
 
 
4588
    /* "bzrlib/_btree_serializer_pyx.pyx":657
 
4589
 *         record = NULL
 
4590
 *         if self.last_record != NULL and key is self.last_key:
 
4591
 *             record = self.last_record             # <<<<<<<<<<<<<<
 
4592
 *         elif _key_to_sha1(key, sha1):
 
4593
 *             record = self._lookup_record(sha1)
 
4594
 */
 
4595
    __pyx_v_record = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record;
 
4596
    goto __pyx_L5;
 
4597
  }
 
4598
 
 
4599
  /* "bzrlib/_btree_serializer_pyx.pyx":658
 
4600
 *         if self.last_record != NULL and key is self.last_key:
 
4601
 *             record = self.last_record
 
4602
 *         elif _key_to_sha1(key, sha1):             # <<<<<<<<<<<<<<
 
4603
 *             record = self._lookup_record(sha1)
 
4604
 *         if record == NULL:
 
4605
 */
 
4606
  __pyx_t_4 = __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(__pyx_v_key, __pyx_v_sha1);
 
4607
  if (__pyx_t_4) {
 
4608
 
 
4609
    /* "bzrlib/_btree_serializer_pyx.pyx":659
 
4610
 *             record = self.last_record
 
4611
 *         elif _key_to_sha1(key, sha1):
 
4612
 *             record = self._lookup_record(sha1)             # <<<<<<<<<<<<<<
 
4613
 *         if record == NULL:
 
4614
 *             raise KeyError('key %r is not present' % (key,))
 
4615
 */
 
4616
    __pyx_t_5 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_lookup_record(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self), __pyx_v_sha1); if (unlikely(__pyx_t_5 == NULL && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4617
    __pyx_v_record = __pyx_t_5;
 
4618
    goto __pyx_L5;
 
4619
  }
 
4620
  __pyx_L5:;
 
4621
 
 
4622
  /* "bzrlib/_btree_serializer_pyx.pyx":660
 
4623
 *         elif _key_to_sha1(key, sha1):
 
4624
 *             record = self._lookup_record(sha1)
 
4625
 *         if record == NULL:             # <<<<<<<<<<<<<<
 
4626
 *             raise KeyError('key %r is not present' % (key,))
 
4627
 *         return self._record_to_value_and_refs(record)
 
4628
 */
 
4629
  __pyx_t_3 = (__pyx_v_record == NULL);
 
4630
  if (__pyx_t_3) {
 
4631
 
 
4632
    /* "bzrlib/_btree_serializer_pyx.pyx":661
 
4633
 *             record = self._lookup_record(sha1)
 
4634
 *         if record == NULL:
 
4635
 *             raise KeyError('key %r is not present' % (key,))             # <<<<<<<<<<<<<<
 
4636
 *         return self._record_to_value_and_refs(record)
 
4637
 * 
 
4638
 */
 
4639
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4640
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
 
4641
    __Pyx_INCREF(__pyx_v_key);
 
4642
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_key);
 
4643
    __Pyx_GIVEREF(__pyx_v_key);
 
4644
    __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_27), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4645
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
 
4646
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
 
4647
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4648
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
 
4649
    PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_7));
 
4650
    __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
 
4651
    __pyx_t_7 = 0;
 
4652
    __pyx_t_7 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4653
    __Pyx_GOTREF(__pyx_t_7);
 
4654
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
 
4655
    __Pyx_Raise(__pyx_t_7, 0, 0);
 
4656
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 
4657
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4658
    goto __pyx_L6;
 
4659
  }
 
4660
  __pyx_L6:;
 
4661
 
 
4662
  /* "bzrlib/_btree_serializer_pyx.pyx":662
 
4663
 *         if record == NULL:
 
4664
 *             raise KeyError('key %r is not present' % (key,))
 
4665
 *         return self._record_to_value_and_refs(record)             # <<<<<<<<<<<<<<
 
4666
 * 
 
4667
 *     def __len__(self):
 
4668
 */
 
4669
  __Pyx_XDECREF(__pyx_r);
 
4670
  __pyx_t_7 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_record_to_value_and_refs(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self), __pyx_v_record)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4671
  __Pyx_GOTREF(__pyx_t_7);
 
4672
  __pyx_r = __pyx_t_7;
 
4673
  __pyx_t_7 = 0;
 
4674
  goto __pyx_L0;
 
4675
 
 
4676
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
4677
  goto __pyx_L0;
 
4678
  __pyx_L1_error:;
 
4679
  __Pyx_XDECREF(__pyx_t_6);
 
4680
  __Pyx_XDECREF(__pyx_t_7);
 
4681
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__getitem__");
 
4682
  __pyx_r = NULL;
 
4683
  __pyx_L0:;
 
4684
  __Pyx_XGIVEREF(__pyx_r);
 
4685
  __Pyx_RefNannyFinishContext();
 
4686
  return __pyx_r;
 
4687
}
 
4688
 
 
4689
/* "bzrlib/_btree_serializer_pyx.pyx":664
 
4690
 *         return self._record_to_value_and_refs(record)
 
4691
 * 
 
4692
 *     def __len__(self):             # <<<<<<<<<<<<<<
 
4693
 *         return self.num_records
 
4694
 * 
 
4695
 */
 
4696
 
 
4697
static Py_ssize_t __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_5__len__(PyObject *__pyx_v_self); /*proto*/
 
4698
static Py_ssize_t __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_5__len__(PyObject *__pyx_v_self) {
 
4699
  Py_ssize_t __pyx_r;
 
4700
  __Pyx_RefNannySetupContext("__len__");
 
4701
 
 
4702
  /* "bzrlib/_btree_serializer_pyx.pyx":665
 
4703
 * 
 
4704
 *     def __len__(self):
 
4705
 *         return self.num_records             # <<<<<<<<<<<<<<
 
4706
 * 
 
4707
 *     def all_keys(self):
 
4708
 */
 
4709
  __pyx_r = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records;
 
4710
  goto __pyx_L0;
 
4711
 
 
4712
  __pyx_r = 0;
 
4713
  __pyx_L0:;
 
4714
  __Pyx_RefNannyFinishContext();
 
4715
  return __pyx_r;
 
4716
}
 
4717
 
 
4718
/* "bzrlib/_btree_serializer_pyx.pyx":667
 
4719
 *         return self.num_records
 
4720
 * 
 
4721
 *     def all_keys(self):             # <<<<<<<<<<<<<<
 
4722
 *         cdef int i
 
4723
 *         result = []
 
4724
 */
 
4725
 
 
4726
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_6all_keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
 
4727
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_6all_keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
 
4728
  int __pyx_v_i;
 
4729
  PyObject *__pyx_v_result;
 
4730
  PyObject *__pyx_r = NULL;
 
4731
  PyObject *__pyx_t_1 = NULL;
 
4732
  int __pyx_t_2;
 
4733
  int __pyx_t_3;
 
4734
  __Pyx_RefNannySetupContext("all_keys");
 
4735
  __pyx_v_result = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
 
4736
 
 
4737
  /* "bzrlib/_btree_serializer_pyx.pyx":669
 
4738
 *     def all_keys(self):
 
4739
 *         cdef int i
 
4740
 *         result = []             # <<<<<<<<<<<<<<
 
4741
 *         for i from 0 <= i < self.num_records:
 
4742
 *             PyList_Append(result, _sha1_to_key(self.records[i].sha1))
 
4743
 */
 
4744
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4745
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
4746
  __Pyx_DECREF(((PyObject *)__pyx_v_result));
 
4747
  __pyx_v_result = __pyx_t_1;
 
4748
  __pyx_t_1 = 0;
 
4749
 
 
4750
  /* "bzrlib/_btree_serializer_pyx.pyx":670
 
4751
 *         cdef int i
 
4752
 *         result = []
 
4753
 *         for i from 0 <= i < self.num_records:             # <<<<<<<<<<<<<<
 
4754
 *             PyList_Append(result, _sha1_to_key(self.records[i].sha1))
 
4755
 *         return result
 
4756
 */
 
4757
  __pyx_t_2 = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records;
 
4758
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {
 
4759
 
 
4760
    /* "bzrlib/_btree_serializer_pyx.pyx":671
 
4761
 *         result = []
 
4762
 *         for i from 0 <= i < self.num_records:
 
4763
 *             PyList_Append(result, _sha1_to_key(self.records[i].sha1))             # <<<<<<<<<<<<<<
 
4764
 *         return result
 
4765
 * 
 
4766
 */
 
4767
    __pyx_t_1 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[__pyx_v_i]).sha1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4768
    __Pyx_GOTREF(__pyx_t_1);
 
4769
    __pyx_t_3 = PyList_Append(((PyObject *)__pyx_v_result), __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4770
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
4771
  }
 
4772
 
 
4773
  /* "bzrlib/_btree_serializer_pyx.pyx":672
 
4774
 *         for i from 0 <= i < self.num_records:
 
4775
 *             PyList_Append(result, _sha1_to_key(self.records[i].sha1))
 
4776
 *         return result             # <<<<<<<<<<<<<<
 
4777
 * 
 
4778
 *     def all_items(self):
 
4779
 */
 
4780
  __Pyx_XDECREF(__pyx_r);
 
4781
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
 
4782
  __pyx_r = ((PyObject *)__pyx_v_result);
 
4783
  goto __pyx_L0;
 
4784
 
 
4785
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
4786
  goto __pyx_L0;
 
4787
  __pyx_L1_error:;
 
4788
  __Pyx_XDECREF(__pyx_t_1);
 
4789
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.all_keys");
 
4790
  __pyx_r = NULL;
 
4791
  __pyx_L0:;
 
4792
  __Pyx_DECREF(__pyx_v_result);
 
4793
  __Pyx_XGIVEREF(__pyx_r);
 
4794
  __Pyx_RefNannyFinishContext();
 
4795
  return __pyx_r;
 
4796
}
 
4797
 
 
4798
/* "bzrlib/_btree_serializer_pyx.pyx":674
 
4799
 *         return result
 
4800
 * 
 
4801
 *     def all_items(self):             # <<<<<<<<<<<<<<
 
4802
 *         cdef int i
 
4803
 *         result = []
 
4804
 */
 
4805
 
 
4806
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7all_items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
 
4807
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7all_items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
 
4808
  int __pyx_v_i;
 
4809
  PyObject *__pyx_v_result;
 
4810
  StaticTuple *__pyx_v_item;
 
4811
  PyObject *__pyx_r = NULL;
 
4812
  PyObject *__pyx_t_1 = NULL;
 
4813
  int __pyx_t_2;
 
4814
  int __pyx_t_3;
 
4815
  __Pyx_RefNannySetupContext("all_items");
 
4816
  __pyx_v_result = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
 
4817
  __pyx_v_item = ((StaticTuple *)Py_None); __Pyx_INCREF(Py_None);
 
4818
 
 
4819
  /* "bzrlib/_btree_serializer_pyx.pyx":676
 
4820
 *     def all_items(self):
 
4821
 *         cdef int i
 
4822
 *         result = []             # <<<<<<<<<<<<<<
 
4823
 *         for i from 0 <= i < self.num_records:
 
4824
 *             item = self._record_to_item(&self.records[i])
 
4825
 */
 
4826
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4827
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
4828
  __Pyx_DECREF(((PyObject *)__pyx_v_result));
 
4829
  __pyx_v_result = __pyx_t_1;
 
4830
  __pyx_t_1 = 0;
 
4831
 
 
4832
  /* "bzrlib/_btree_serializer_pyx.pyx":677
 
4833
 *         cdef int i
 
4834
 *         result = []
 
4835
 *         for i from 0 <= i < self.num_records:             # <<<<<<<<<<<<<<
 
4836
 *             item = self._record_to_item(&self.records[i])
 
4837
 *             PyList_Append(result, item)
 
4838
 */
 
4839
  __pyx_t_2 = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records;
 
4840
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {
 
4841
 
 
4842
    /* "bzrlib/_btree_serializer_pyx.pyx":678
 
4843
 *         result = []
 
4844
 *         for i from 0 <= i < self.num_records:
 
4845
 *             item = self._record_to_item(&self.records[i])             # <<<<<<<<<<<<<<
 
4846
 *             PyList_Append(result, item)
 
4847
 *         return result
 
4848
 */
 
4849
    __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_record_to_item(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self), (&(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[__pyx_v_i])))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4850
    __Pyx_GOTREF(__pyx_t_1);
 
4851
    __Pyx_DECREF(((PyObject *)__pyx_v_item));
 
4852
    __pyx_v_item = ((StaticTuple *)__pyx_t_1);
 
4853
    __pyx_t_1 = 0;
 
4854
 
 
4855
    /* "bzrlib/_btree_serializer_pyx.pyx":679
 
4856
 *         for i from 0 <= i < self.num_records:
 
4857
 *             item = self._record_to_item(&self.records[i])
 
4858
 *             PyList_Append(result, item)             # <<<<<<<<<<<<<<
 
4859
 *         return result
 
4860
 * 
 
4861
 */
 
4862
    __pyx_t_3 = PyList_Append(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_v_item)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
4863
  }
 
4864
 
 
4865
  /* "bzrlib/_btree_serializer_pyx.pyx":680
 
4866
 *             item = self._record_to_item(&self.records[i])
 
4867
 *             PyList_Append(result, item)
 
4868
 *         return result             # <<<<<<<<<<<<<<
 
4869
 * 
 
4870
 *     cdef int _count_records(self, char *c_content, char *c_end): # cannot_raise
 
4871
 */
 
4872
  __Pyx_XDECREF(__pyx_r);
 
4873
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
 
4874
  __pyx_r = ((PyObject *)__pyx_v_result);
 
4875
  goto __pyx_L0;
 
4876
 
 
4877
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
4878
  goto __pyx_L0;
 
4879
  __pyx_L1_error:;
 
4880
  __Pyx_XDECREF(__pyx_t_1);
 
4881
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.all_items");
 
4882
  __pyx_r = NULL;
 
4883
  __pyx_L0:;
 
4884
  __Pyx_DECREF(__pyx_v_result);
 
4885
  __Pyx_DECREF((PyObject *)__pyx_v_item);
 
4886
  __Pyx_XGIVEREF(__pyx_r);
 
4887
  __Pyx_RefNannyFinishContext();
 
4888
  return __pyx_r;
 
4889
}
 
4890
 
 
4891
/* "bzrlib/_btree_serializer_pyx.pyx":682
 
4892
 *         return result
 
4893
 * 
 
4894
 *     cdef int _count_records(self, char *c_content, char *c_end): # cannot_raise             # <<<<<<<<<<<<<<
 
4895
 *         """Count how many records are in this section."""
 
4896
 *         cdef char *c_cur
 
4897
 */
 
4898
 
 
4899
static  int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__count_records(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self, char *__pyx_v_c_content, char *__pyx_v_c_end) {
 
4900
  char *__pyx_v_c_cur;
 
4901
  int __pyx_v_num_records;
 
4902
  int __pyx_r;
 
4903
  int __pyx_t_1;
 
4904
  int __pyx_t_2;
 
4905
  int __pyx_t_3;
 
4906
  __Pyx_RefNannySetupContext("_count_records");
 
4907
 
 
4908
  /* "bzrlib/_btree_serializer_pyx.pyx":687
 
4909
 *         cdef int num_records
 
4910
 * 
 
4911
 *         c_cur = c_content             # <<<<<<<<<<<<<<
 
4912
 *         num_records = 0
 
4913
 *         while c_cur != NULL and c_cur < c_end:
 
4914
 */
 
4915
  __pyx_v_c_cur = __pyx_v_c_content;
 
4916
 
 
4917
  /* "bzrlib/_btree_serializer_pyx.pyx":688
 
4918
 * 
 
4919
 *         c_cur = c_content
 
4920
 *         num_records = 0             # <<<<<<<<<<<<<<
 
4921
 *         while c_cur != NULL and c_cur < c_end:
 
4922
 *             c_cur = <char *>memchr(c_cur, c'\n', c_end - c_cur);
 
4923
 */
 
4924
  __pyx_v_num_records = 0;
 
4925
 
 
4926
  /* "bzrlib/_btree_serializer_pyx.pyx":689
 
4927
 *         c_cur = c_content
 
4928
 *         num_records = 0
 
4929
 *         while c_cur != NULL and c_cur < c_end:             # <<<<<<<<<<<<<<
 
4930
 *             c_cur = <char *>memchr(c_cur, c'\n', c_end - c_cur);
 
4931
 *             if c_cur == NULL:
 
4932
 */
 
4933
  while (1) {
 
4934
    __pyx_t_1 = (__pyx_v_c_cur != NULL);
 
4935
    if (__pyx_t_1) {
 
4936
      __pyx_t_2 = (__pyx_v_c_cur < __pyx_v_c_end);
 
4937
      __pyx_t_3 = __pyx_t_2;
 
4938
    } else {
 
4939
      __pyx_t_3 = __pyx_t_1;
 
4940
    }
 
4941
    if (!__pyx_t_3) break;
 
4942
 
 
4943
    /* "bzrlib/_btree_serializer_pyx.pyx":690
 
4944
 *         num_records = 0
 
4945
 *         while c_cur != NULL and c_cur < c_end:
 
4946
 *             c_cur = <char *>memchr(c_cur, c'\n', c_end - c_cur);             # <<<<<<<<<<<<<<
 
4947
 *             if c_cur == NULL:
 
4948
 *                 break
 
4949
 */
 
4950
    __pyx_v_c_cur = ((char *)memchr(__pyx_v_c_cur, '\n', (__pyx_v_c_end - __pyx_v_c_cur)));
 
4951
 
 
4952
    /* "bzrlib/_btree_serializer_pyx.pyx":691
 
4953
 *         while c_cur != NULL and c_cur < c_end:
 
4954
 *             c_cur = <char *>memchr(c_cur, c'\n', c_end - c_cur);
 
4955
 *             if c_cur == NULL:             # <<<<<<<<<<<<<<
 
4956
 *                 break
 
4957
 *             c_cur = c_cur + 1
 
4958
 */
 
4959
    __pyx_t_3 = (__pyx_v_c_cur == NULL);
 
4960
    if (__pyx_t_3) {
 
4961
 
 
4962
      /* "bzrlib/_btree_serializer_pyx.pyx":692
 
4963
 *             c_cur = <char *>memchr(c_cur, c'\n', c_end - c_cur);
 
4964
 *             if c_cur == NULL:
 
4965
 *                 break             # <<<<<<<<<<<<<<
 
4966
 *             c_cur = c_cur + 1
 
4967
 *             num_records = num_records + 1
 
4968
 */
 
4969
      goto __pyx_L4_break;
 
4970
      goto __pyx_L5;
 
4971
    }
 
4972
    __pyx_L5:;
 
4973
 
 
4974
    /* "bzrlib/_btree_serializer_pyx.pyx":693
 
4975
 *             if c_cur == NULL:
 
4976
 *                 break
 
4977
 *             c_cur = c_cur + 1             # <<<<<<<<<<<<<<
 
4978
 *             num_records = num_records + 1
 
4979
 *         return num_records
 
4980
 */
 
4981
    __pyx_v_c_cur = (__pyx_v_c_cur + 1);
 
4982
 
 
4983
    /* "bzrlib/_btree_serializer_pyx.pyx":694
 
4984
 *                 break
 
4985
 *             c_cur = c_cur + 1
 
4986
 *             num_records = num_records + 1             # <<<<<<<<<<<<<<
 
4987
 *         return num_records
 
4988
 * 
 
4989
 */
 
4990
    __pyx_v_num_records = (__pyx_v_num_records + 1);
 
4991
  }
 
4992
  __pyx_L4_break:;
 
4993
 
 
4994
  /* "bzrlib/_btree_serializer_pyx.pyx":695
 
4995
 *             c_cur = c_cur + 1
 
4996
 *             num_records = num_records + 1
 
4997
 *         return num_records             # <<<<<<<<<<<<<<
 
4998
 * 
 
4999
 *     cdef _parse_bytes(self, bytes):
 
5000
 */
 
5001
  __pyx_r = __pyx_v_num_records;
 
5002
  goto __pyx_L0;
 
5003
 
 
5004
  __pyx_r = 0;
 
5005
  __pyx_L0:;
 
5006
  __Pyx_RefNannyFinishContext();
 
5007
  return __pyx_r;
 
5008
}
 
5009
 
 
5010
/* "bzrlib/_btree_serializer_pyx.pyx":697
 
5011
 *         return num_records
 
5012
 * 
 
5013
 *     cdef _parse_bytes(self, bytes):             # <<<<<<<<<<<<<<
 
5014
 *         """Parse the string 'bytes' into content."""
 
5015
 *         cdef char *c_bytes
 
5016
 */
 
5017
 
 
5018
static  PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_bytes(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self, PyObject *__pyx_v_bytes) {
 
5019
  char *__pyx_v_c_bytes;
 
5020
  char *__pyx_v_c_cur;
 
5021
  char *__pyx_v_c_end;
 
5022
  Py_ssize_t __pyx_v_n_bytes;
 
5023
  int __pyx_v_num_records;
 
5024
  int __pyx_v_entry;
 
5025
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_cur_record;
 
5026
  PyObject *__pyx_r = NULL;
 
5027
  int __pyx_t_1;
 
5028
  PyObject *__pyx_t_2 = NULL;
 
5029
  int __pyx_t_3;
 
5030
  PyObject *__pyx_t_4 = NULL;
 
5031
  int __pyx_t_5;
 
5032
  int __pyx_t_6;
 
5033
  int __pyx_t_7;
 
5034
  char *__pyx_t_8;
 
5035
  __Pyx_RefNannySetupContext("_parse_bytes");
 
5036
 
 
5037
  /* "bzrlib/_btree_serializer_pyx.pyx":707
 
5038
 *         cdef gc_chk_sha1_record *cur_record
 
5039
 * 
 
5040
 *         if not PyString_CheckExact(bytes):             # <<<<<<<<<<<<<<
 
5041
 *             raise TypeError('We only support parsing plain 8-bit strings.')
 
5042
 *         # Pass 1, count how many records there will be
 
5043
 */
 
5044
  __pyx_t_1 = (!PyString_CheckExact(__pyx_v_bytes));
 
5045
  if (__pyx_t_1) {
 
5046
 
 
5047
    /* "bzrlib/_btree_serializer_pyx.pyx":708
 
5048
 * 
 
5049
 *         if not PyString_CheckExact(bytes):
 
5050
 *             raise TypeError('We only support parsing plain 8-bit strings.')             # <<<<<<<<<<<<<<
 
5051
 *         # Pass 1, count how many records there will be
 
5052
 *         n_bytes = PyString_GET_SIZE(bytes)
 
5053
 */
 
5054
    __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5055
    __Pyx_GOTREF(__pyx_t_2);
 
5056
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5057
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5058
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5059
    goto __pyx_L3;
 
5060
  }
 
5061
  __pyx_L3:;
 
5062
 
 
5063
  /* "bzrlib/_btree_serializer_pyx.pyx":710
 
5064
 *             raise TypeError('We only support parsing plain 8-bit strings.')
 
5065
 *         # Pass 1, count how many records there will be
 
5066
 *         n_bytes = PyString_GET_SIZE(bytes)             # <<<<<<<<<<<<<<
 
5067
 *         c_bytes = PyString_AS_STRING(bytes)
 
5068
 *         c_end = c_bytes + n_bytes
 
5069
 */
 
5070
  __pyx_v_n_bytes = PyString_GET_SIZE(__pyx_v_bytes);
 
5071
 
 
5072
  /* "bzrlib/_btree_serializer_pyx.pyx":711
 
5073
 *         # Pass 1, count how many records there will be
 
5074
 *         n_bytes = PyString_GET_SIZE(bytes)
 
5075
 *         c_bytes = PyString_AS_STRING(bytes)             # <<<<<<<<<<<<<<
 
5076
 *         c_end = c_bytes + n_bytes
 
5077
 *         if strncmp(c_bytes, 'type=leaf\n', 10):
 
5078
 */
 
5079
  __pyx_v_c_bytes = PyString_AS_STRING(__pyx_v_bytes);
 
5080
 
 
5081
  /* "bzrlib/_btree_serializer_pyx.pyx":712
 
5082
 *         n_bytes = PyString_GET_SIZE(bytes)
 
5083
 *         c_bytes = PyString_AS_STRING(bytes)
 
5084
 *         c_end = c_bytes + n_bytes             # <<<<<<<<<<<<<<
 
5085
 *         if strncmp(c_bytes, 'type=leaf\n', 10):
 
5086
 *             raise ValueError("bytes did not start with 'type=leaf\\n': %r"
 
5087
 */
 
5088
  __pyx_v_c_end = (__pyx_v_c_bytes + __pyx_v_n_bytes);
 
5089
 
 
5090
  /* "bzrlib/_btree_serializer_pyx.pyx":713
 
5091
 *         c_bytes = PyString_AS_STRING(bytes)
 
5092
 *         c_end = c_bytes + n_bytes
 
5093
 *         if strncmp(c_bytes, 'type=leaf\n', 10):             # <<<<<<<<<<<<<<
 
5094
 *             raise ValueError("bytes did not start with 'type=leaf\\n': %r"
 
5095
 *                              % (bytes[:10],))
 
5096
 */
 
5097
  __pyx_t_3 = strncmp(__pyx_v_c_bytes, __pyx_k_30, 10);
 
5098
  if (__pyx_t_3) {
 
5099
 
 
5100
    /* "bzrlib/_btree_serializer_pyx.pyx":715
 
5101
 *         if strncmp(c_bytes, 'type=leaf\n', 10):
 
5102
 *             raise ValueError("bytes did not start with 'type=leaf\\n': %r"
 
5103
 *                              % (bytes[:10],))             # <<<<<<<<<<<<<<
 
5104
 *         c_cur = c_bytes + 10
 
5105
 *         num_records = self._count_records(c_cur, c_end)
 
5106
 */
 
5107
    __pyx_t_2 = __Pyx_PySequence_GetSlice(__pyx_v_bytes, 0, 10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5108
    __Pyx_GOTREF(__pyx_t_2);
 
5109
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5110
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
5111
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
 
5112
    __Pyx_GIVEREF(__pyx_t_2);
 
5113
    __pyx_t_2 = 0;
 
5114
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_31), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5115
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
 
5116
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
5117
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5118
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
5119
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2));
 
5120
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
 
5121
    __pyx_t_2 = 0;
 
5122
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5123
    __Pyx_GOTREF(__pyx_t_2);
 
5124
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
5125
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5126
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5127
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5128
    goto __pyx_L4;
 
5129
  }
 
5130
  __pyx_L4:;
 
5131
 
 
5132
  /* "bzrlib/_btree_serializer_pyx.pyx":716
 
5133
 *             raise ValueError("bytes did not start with 'type=leaf\\n': %r"
 
5134
 *                              % (bytes[:10],))
 
5135
 *         c_cur = c_bytes + 10             # <<<<<<<<<<<<<<
 
5136
 *         num_records = self._count_records(c_cur, c_end)
 
5137
 *         # Now allocate the memory for these items, and go to town
 
5138
 */
 
5139
  __pyx_v_c_cur = (__pyx_v_c_bytes + 10);
 
5140
 
 
5141
  /* "bzrlib/_btree_serializer_pyx.pyx":717
 
5142
 *                              % (bytes[:10],))
 
5143
 *         c_cur = c_bytes + 10
 
5144
 *         num_records = self._count_records(c_cur, c_end)             # <<<<<<<<<<<<<<
 
5145
 *         # Now allocate the memory for these items, and go to town
 
5146
 *         self.records = <gc_chk_sha1_record*>PyMem_Malloc(num_records *
 
5147
 */
 
5148
  __pyx_v_num_records = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_count_records(__pyx_v_self, __pyx_v_c_cur, __pyx_v_c_end);
 
5149
 
 
5150
  /* "bzrlib/_btree_serializer_pyx.pyx":719
 
5151
 *         num_records = self._count_records(c_cur, c_end)
 
5152
 *         # Now allocate the memory for these items, and go to town
 
5153
 *         self.records = <gc_chk_sha1_record*>PyMem_Malloc(num_records *             # <<<<<<<<<<<<<<
 
5154
 *             (sizeof(unsigned short) + sizeof(gc_chk_sha1_record)))
 
5155
 *         self.num_records = num_records
 
5156
 */
 
5157
  __pyx_v_self->records = ((__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *)PyMem_Malloc((__pyx_v_num_records * ((sizeof(unsigned short)) + (sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record))))));
 
5158
 
 
5159
  /* "bzrlib/_btree_serializer_pyx.pyx":721
 
5160
 *         self.records = <gc_chk_sha1_record*>PyMem_Malloc(num_records *
 
5161
 *             (sizeof(unsigned short) + sizeof(gc_chk_sha1_record)))
 
5162
 *         self.num_records = num_records             # <<<<<<<<<<<<<<
 
5163
 *         cur_record = self.records
 
5164
 *         entry = 0
 
5165
 */
 
5166
  __pyx_v_self->num_records = __pyx_v_num_records;
 
5167
 
 
5168
  /* "bzrlib/_btree_serializer_pyx.pyx":722
 
5169
 *             (sizeof(unsigned short) + sizeof(gc_chk_sha1_record)))
 
5170
 *         self.num_records = num_records
 
5171
 *         cur_record = self.records             # <<<<<<<<<<<<<<
 
5172
 *         entry = 0
 
5173
 *         while c_cur != NULL and c_cur < c_end and entry < num_records:
 
5174
 */
 
5175
  __pyx_v_cur_record = __pyx_v_self->records;
 
5176
 
 
5177
  /* "bzrlib/_btree_serializer_pyx.pyx":723
 
5178
 *         self.num_records = num_records
 
5179
 *         cur_record = self.records
 
5180
 *         entry = 0             # <<<<<<<<<<<<<<
 
5181
 *         while c_cur != NULL and c_cur < c_end and entry < num_records:
 
5182
 *             c_cur = self._parse_one_entry(c_cur, c_end, cur_record)
 
5183
 */
 
5184
  __pyx_v_entry = 0;
 
5185
 
 
5186
  /* "bzrlib/_btree_serializer_pyx.pyx":724
 
5187
 *         cur_record = self.records
 
5188
 *         entry = 0
 
5189
 *         while c_cur != NULL and c_cur < c_end and entry < num_records:             # <<<<<<<<<<<<<<
 
5190
 *             c_cur = self._parse_one_entry(c_cur, c_end, cur_record)
 
5191
 *             cur_record = cur_record + 1
 
5192
 */
 
5193
  while (1) {
 
5194
    __pyx_t_1 = (__pyx_v_c_cur != NULL);
 
5195
    if (__pyx_t_1) {
 
5196
      __pyx_t_5 = (__pyx_v_c_cur < __pyx_v_c_end);
 
5197
      if (__pyx_t_5) {
 
5198
        __pyx_t_6 = (__pyx_v_entry < __pyx_v_num_records);
 
5199
        __pyx_t_7 = __pyx_t_6;
 
5200
      } else {
 
5201
        __pyx_t_7 = __pyx_t_5;
 
5202
      }
 
5203
      __pyx_t_5 = __pyx_t_7;
 
5204
    } else {
 
5205
      __pyx_t_5 = __pyx_t_1;
 
5206
    }
 
5207
    if (!__pyx_t_5) break;
 
5208
 
 
5209
    /* "bzrlib/_btree_serializer_pyx.pyx":725
 
5210
 *         entry = 0
 
5211
 *         while c_cur != NULL and c_cur < c_end and entry < num_records:
 
5212
 *             c_cur = self._parse_one_entry(c_cur, c_end, cur_record)             # <<<<<<<<<<<<<<
 
5213
 *             cur_record = cur_record + 1
 
5214
 *             entry = entry + 1
 
5215
 */
 
5216
    __pyx_t_8 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_parse_one_entry(__pyx_v_self, __pyx_v_c_cur, __pyx_v_c_end, __pyx_v_cur_record); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5217
    __pyx_v_c_cur = __pyx_t_8;
 
5218
 
 
5219
    /* "bzrlib/_btree_serializer_pyx.pyx":726
 
5220
 *         while c_cur != NULL and c_cur < c_end and entry < num_records:
 
5221
 *             c_cur = self._parse_one_entry(c_cur, c_end, cur_record)
 
5222
 *             cur_record = cur_record + 1             # <<<<<<<<<<<<<<
 
5223
 *             entry = entry + 1
 
5224
 *         if (entry != self.num_records
 
5225
 */
 
5226
    __pyx_v_cur_record = (__pyx_v_cur_record + 1);
 
5227
 
 
5228
    /* "bzrlib/_btree_serializer_pyx.pyx":727
 
5229
 *             c_cur = self._parse_one_entry(c_cur, c_end, cur_record)
 
5230
 *             cur_record = cur_record + 1
 
5231
 *             entry = entry + 1             # <<<<<<<<<<<<<<
 
5232
 *         if (entry != self.num_records
 
5233
 *             or c_cur != c_end
 
5234
 */
 
5235
    __pyx_v_entry = (__pyx_v_entry + 1);
 
5236
  }
 
5237
 
 
5238
  /* "bzrlib/_btree_serializer_pyx.pyx":728
 
5239
 *             cur_record = cur_record + 1
 
5240
 *             entry = entry + 1
 
5241
 *         if (entry != self.num_records             # <<<<<<<<<<<<<<
 
5242
 *             or c_cur != c_end
 
5243
 *             or cur_record != self.records + self.num_records):
 
5244
 */
 
5245
  __pyx_t_5 = (__pyx_v_entry != __pyx_v_self->num_records);
 
5246
  if (!__pyx_t_5) {
 
5247
 
 
5248
    /* "bzrlib/_btree_serializer_pyx.pyx":730
 
5249
 *         if (entry != self.num_records
 
5250
 *             or c_cur != c_end
 
5251
 *             or cur_record != self.records + self.num_records):             # <<<<<<<<<<<<<<
 
5252
 *             raise ValueError('Something went wrong while parsing.')
 
5253
 *         # Pass 3: build the offset map
 
5254
 */
 
5255
    __pyx_t_1 = (__pyx_v_c_cur != __pyx_v_c_end);
 
5256
    if (!__pyx_t_1) {
 
5257
      __pyx_t_7 = (__pyx_v_cur_record != (__pyx_v_self->records + __pyx_v_self->num_records));
 
5258
      __pyx_t_6 = __pyx_t_7;
 
5259
    } else {
 
5260
      __pyx_t_6 = __pyx_t_1;
 
5261
    }
 
5262
    __pyx_t_1 = __pyx_t_6;
 
5263
  } else {
 
5264
    __pyx_t_1 = __pyx_t_5;
 
5265
  }
 
5266
  if (__pyx_t_1) {
 
5267
 
 
5268
    /* "bzrlib/_btree_serializer_pyx.pyx":731
 
5269
 *             or c_cur != c_end
 
5270
 *             or cur_record != self.records + self.num_records):
 
5271
 *             raise ValueError('Something went wrong while parsing.')             # <<<<<<<<<<<<<<
 
5272
 *         # Pass 3: build the offset map
 
5273
 *         self._compute_common()
 
5274
 */
 
5275
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5276
    __Pyx_GOTREF(__pyx_t_2);
 
5277
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5278
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5279
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5280
    goto __pyx_L7;
 
5281
  }
 
5282
  __pyx_L7:;
 
5283
 
 
5284
  /* "bzrlib/_btree_serializer_pyx.pyx":733
 
5285
 *             raise ValueError('Something went wrong while parsing.')
 
5286
 *         # Pass 3: build the offset map
 
5287
 *         self._compute_common()             # <<<<<<<<<<<<<<
 
5288
 * 
 
5289
 *     cdef char *_parse_one_entry(self, char *c_cur, char *c_end,
 
5290
 */
 
5291
  __pyx_t_2 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_compute_common(__pyx_v_self); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5292
  __Pyx_GOTREF(__pyx_t_2);
 
5293
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5294
 
 
5295
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
5296
  goto __pyx_L0;
 
5297
  __pyx_L1_error:;
 
5298
  __Pyx_XDECREF(__pyx_t_2);
 
5299
  __Pyx_XDECREF(__pyx_t_4);
 
5300
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._parse_bytes");
 
5301
  __pyx_r = 0;
 
5302
  __pyx_L0:;
 
5303
  __Pyx_XGIVEREF(__pyx_r);
 
5304
  __Pyx_RefNannyFinishContext();
 
5305
  return __pyx_r;
 
5306
}
 
5307
 
 
5308
/* "bzrlib/_btree_serializer_pyx.pyx":735
 
5309
 *         self._compute_common()
 
5310
 * 
 
5311
 *     cdef char *_parse_one_entry(self, char *c_cur, char *c_end,             # <<<<<<<<<<<<<<
 
5312
 *                                 gc_chk_sha1_record *cur_record) except NULL:
 
5313
 *         """Read a single sha record from the bytes.
 
5314
 */
 
5315
 
 
5316
static  char *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_one_entry(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self, char *__pyx_v_c_cur, char *__pyx_v_c_end, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_cur_record) {
 
5317
  char *__pyx_v_c_next;
 
5318
  char *__pyx_r;
 
5319
  int __pyx_t_1;
 
5320
  PyObject *__pyx_t_2 = NULL;
 
5321
  PyObject *__pyx_t_3 = NULL;
 
5322
  int __pyx_t_4;
 
5323
  int __pyx_t_5;
 
5324
  int __pyx_t_6;
 
5325
  __Pyx_RefNannySetupContext("_parse_one_entry");
 
5326
 
 
5327
  /* "bzrlib/_btree_serializer_pyx.pyx":742
 
5328
 *         """
 
5329
 *         cdef char *c_next
 
5330
 *         if strncmp(c_cur, 'sha1:', 5):             # <<<<<<<<<<<<<<
 
5331
 *             raise ValueError('line did not start with sha1: %r'
 
5332
 *                 % (safe_string_from_size(c_cur, 10),))
 
5333
 */
 
5334
  __pyx_t_1 = strncmp(__pyx_v_c_cur, __pyx_k_3, 5);
 
5335
  if (__pyx_t_1) {
 
5336
 
 
5337
    /* "bzrlib/_btree_serializer_pyx.pyx":744
 
5338
 *         if strncmp(c_cur, 'sha1:', 5):
 
5339
 *             raise ValueError('line did not start with sha1: %r'
 
5340
 *                 % (safe_string_from_size(c_cur, 10),))             # <<<<<<<<<<<<<<
 
5341
 *         c_cur = c_cur + 5
 
5342
 *         c_next = <char *>memchr(c_cur, c'\0', c_end - c_cur)
 
5343
 */
 
5344
    __pyx_t_2 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_c_cur, 10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5345
    __Pyx_GOTREF(__pyx_t_2);
 
5346
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5347
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
5348
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
 
5349
    __Pyx_GIVEREF(__pyx_t_2);
 
5350
    __pyx_t_2 = 0;
 
5351
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_34), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5352
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
 
5353
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
5354
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5355
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
 
5356
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
 
5357
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
 
5358
    __pyx_t_2 = 0;
 
5359
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5360
    __Pyx_GOTREF(__pyx_t_2);
 
5361
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 
5362
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5363
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5364
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5365
    goto __pyx_L3;
 
5366
  }
 
5367
  __pyx_L3:;
 
5368
 
 
5369
  /* "bzrlib/_btree_serializer_pyx.pyx":745
 
5370
 *             raise ValueError('line did not start with sha1: %r'
 
5371
 *                 % (safe_string_from_size(c_cur, 10),))
 
5372
 *         c_cur = c_cur + 5             # <<<<<<<<<<<<<<
 
5373
 *         c_next = <char *>memchr(c_cur, c'\0', c_end - c_cur)
 
5374
 *         if c_next == NULL or (c_next - c_cur != 40):
 
5375
 */
 
5376
  __pyx_v_c_cur = (__pyx_v_c_cur + 5);
 
5377
 
 
5378
  /* "bzrlib/_btree_serializer_pyx.pyx":746
 
5379
 *                 % (safe_string_from_size(c_cur, 10),))
 
5380
 *         c_cur = c_cur + 5
 
5381
 *         c_next = <char *>memchr(c_cur, c'\0', c_end - c_cur)             # <<<<<<<<<<<<<<
 
5382
 *         if c_next == NULL or (c_next - c_cur != 40):
 
5383
 *             raise ValueError('Line did not contain 40 hex bytes')
 
5384
 */
 
5385
  __pyx_v_c_next = ((char *)memchr(__pyx_v_c_cur, '\x00', (__pyx_v_c_end - __pyx_v_c_cur)));
 
5386
 
 
5387
  /* "bzrlib/_btree_serializer_pyx.pyx":747
 
5388
 *         c_cur = c_cur + 5
 
5389
 *         c_next = <char *>memchr(c_cur, c'\0', c_end - c_cur)
 
5390
 *         if c_next == NULL or (c_next - c_cur != 40):             # <<<<<<<<<<<<<<
 
5391
 *             raise ValueError('Line did not contain 40 hex bytes')
 
5392
 *         if not _unhexlify_sha1(c_cur, cur_record.sha1):
 
5393
 */
 
5394
  __pyx_t_4 = (__pyx_v_c_next == NULL);
 
5395
  if (!__pyx_t_4) {
 
5396
    __pyx_t_5 = ((__pyx_v_c_next - __pyx_v_c_cur) != 40);
 
5397
    __pyx_t_6 = __pyx_t_5;
 
5398
  } else {
 
5399
    __pyx_t_6 = __pyx_t_4;
 
5400
  }
 
5401
  if (__pyx_t_6) {
 
5402
 
 
5403
    /* "bzrlib/_btree_serializer_pyx.pyx":748
 
5404
 *         c_next = <char *>memchr(c_cur, c'\0', c_end - c_cur)
 
5405
 *         if c_next == NULL or (c_next - c_cur != 40):
 
5406
 *             raise ValueError('Line did not contain 40 hex bytes')             # <<<<<<<<<<<<<<
 
5407
 *         if not _unhexlify_sha1(c_cur, cur_record.sha1):
 
5408
 *             raise ValueError('We failed to unhexlify')
 
5409
 */
 
5410
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5411
    __Pyx_GOTREF(__pyx_t_2);
 
5412
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5413
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5414
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5415
    goto __pyx_L4;
 
5416
  }
 
5417
  __pyx_L4:;
 
5418
 
 
5419
  /* "bzrlib/_btree_serializer_pyx.pyx":749
 
5420
 *         if c_next == NULL or (c_next - c_cur != 40):
 
5421
 *             raise ValueError('Line did not contain 40 hex bytes')
 
5422
 *         if not _unhexlify_sha1(c_cur, cur_record.sha1):             # <<<<<<<<<<<<<<
 
5423
 *             raise ValueError('We failed to unhexlify')
 
5424
 *         c_cur = c_next + 1
 
5425
 */
 
5426
  __pyx_t_6 = (!__pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(__pyx_v_c_cur, __pyx_v_cur_record->sha1));
 
5427
  if (__pyx_t_6) {
 
5428
 
 
5429
    /* "bzrlib/_btree_serializer_pyx.pyx":750
 
5430
 *             raise ValueError('Line did not contain 40 hex bytes')
 
5431
 *         if not _unhexlify_sha1(c_cur, cur_record.sha1):
 
5432
 *             raise ValueError('We failed to unhexlify')             # <<<<<<<<<<<<<<
 
5433
 *         c_cur = c_next + 1
 
5434
 *         if c_cur[0] != c'\0':
 
5435
 */
 
5436
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5437
    __Pyx_GOTREF(__pyx_t_2);
 
5438
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5439
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5440
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5441
    goto __pyx_L5;
 
5442
  }
 
5443
  __pyx_L5:;
 
5444
 
 
5445
  /* "bzrlib/_btree_serializer_pyx.pyx":751
 
5446
 *         if not _unhexlify_sha1(c_cur, cur_record.sha1):
 
5447
 *             raise ValueError('We failed to unhexlify')
 
5448
 *         c_cur = c_next + 1             # <<<<<<<<<<<<<<
 
5449
 *         if c_cur[0] != c'\0':
 
5450
 *             raise ValueError('only 1 null, not 2 as expected')
 
5451
 */
 
5452
  __pyx_v_c_cur = (__pyx_v_c_next + 1);
 
5453
 
 
5454
  /* "bzrlib/_btree_serializer_pyx.pyx":752
 
5455
 *             raise ValueError('We failed to unhexlify')
 
5456
 *         c_cur = c_next + 1
 
5457
 *         if c_cur[0] != c'\0':             # <<<<<<<<<<<<<<
 
5458
 *             raise ValueError('only 1 null, not 2 as expected')
 
5459
 *         c_cur = c_cur + 1
 
5460
 */
 
5461
  __pyx_t_6 = ((__pyx_v_c_cur[0]) != '\x00');
 
5462
  if (__pyx_t_6) {
 
5463
 
 
5464
    /* "bzrlib/_btree_serializer_pyx.pyx":753
 
5465
 *         c_cur = c_next + 1
 
5466
 *         if c_cur[0] != c'\0':
 
5467
 *             raise ValueError('only 1 null, not 2 as expected')             # <<<<<<<<<<<<<<
 
5468
 *         c_cur = c_cur + 1
 
5469
 *         cur_record.block_offset = strtoll(c_cur, &c_next, 10)
 
5470
 */
 
5471
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5472
    __Pyx_GOTREF(__pyx_t_2);
 
5473
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5474
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5475
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5476
    goto __pyx_L6;
 
5477
  }
 
5478
  __pyx_L6:;
 
5479
 
 
5480
  /* "bzrlib/_btree_serializer_pyx.pyx":754
 
5481
 *         if c_cur[0] != c'\0':
 
5482
 *             raise ValueError('only 1 null, not 2 as expected')
 
5483
 *         c_cur = c_cur + 1             # <<<<<<<<<<<<<<
 
5484
 *         cur_record.block_offset = strtoll(c_cur, &c_next, 10)
 
5485
 *         if c_cur == c_next or c_next[0] != c' ':
 
5486
 */
 
5487
  __pyx_v_c_cur = (__pyx_v_c_cur + 1);
 
5488
 
 
5489
  /* "bzrlib/_btree_serializer_pyx.pyx":755
 
5490
 *             raise ValueError('only 1 null, not 2 as expected')
 
5491
 *         c_cur = c_cur + 1
 
5492
 *         cur_record.block_offset = strtoll(c_cur, &c_next, 10)             # <<<<<<<<<<<<<<
 
5493
 *         if c_cur == c_next or c_next[0] != c' ':
 
5494
 *             raise ValueError('Failed to parse block offset')
 
5495
 */
 
5496
  __pyx_v_cur_record->block_offset = strtoll(__pyx_v_c_cur, (&__pyx_v_c_next), 10);
 
5497
 
 
5498
  /* "bzrlib/_btree_serializer_pyx.pyx":756
 
5499
 *         c_cur = c_cur + 1
 
5500
 *         cur_record.block_offset = strtoll(c_cur, &c_next, 10)
 
5501
 *         if c_cur == c_next or c_next[0] != c' ':             # <<<<<<<<<<<<<<
 
5502
 *             raise ValueError('Failed to parse block offset')
 
5503
 *         c_cur = c_next + 1
 
5504
 */
 
5505
  __pyx_t_6 = (__pyx_v_c_cur == __pyx_v_c_next);
 
5506
  if (!__pyx_t_6) {
 
5507
    __pyx_t_4 = ((__pyx_v_c_next[0]) != ' ');
 
5508
    __pyx_t_5 = __pyx_t_4;
 
5509
  } else {
 
5510
    __pyx_t_5 = __pyx_t_6;
 
5511
  }
 
5512
  if (__pyx_t_5) {
 
5513
 
 
5514
    /* "bzrlib/_btree_serializer_pyx.pyx":757
 
5515
 *         cur_record.block_offset = strtoll(c_cur, &c_next, 10)
 
5516
 *         if c_cur == c_next or c_next[0] != c' ':
 
5517
 *             raise ValueError('Failed to parse block offset')             # <<<<<<<<<<<<<<
 
5518
 *         c_cur = c_next + 1
 
5519
 *         cur_record.block_length = strtoul(c_cur, &c_next, 10)
 
5520
 */
 
5521
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5522
    __Pyx_GOTREF(__pyx_t_2);
 
5523
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5524
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5525
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5526
    goto __pyx_L7;
 
5527
  }
 
5528
  __pyx_L7:;
 
5529
 
 
5530
  /* "bzrlib/_btree_serializer_pyx.pyx":758
 
5531
 *         if c_cur == c_next or c_next[0] != c' ':
 
5532
 *             raise ValueError('Failed to parse block offset')
 
5533
 *         c_cur = c_next + 1             # <<<<<<<<<<<<<<
 
5534
 *         cur_record.block_length = strtoul(c_cur, &c_next, 10)
 
5535
 *         if c_cur == c_next or c_next[0] != c' ':
 
5536
 */
 
5537
  __pyx_v_c_cur = (__pyx_v_c_next + 1);
 
5538
 
 
5539
  /* "bzrlib/_btree_serializer_pyx.pyx":759
 
5540
 *             raise ValueError('Failed to parse block offset')
 
5541
 *         c_cur = c_next + 1
 
5542
 *         cur_record.block_length = strtoul(c_cur, &c_next, 10)             # <<<<<<<<<<<<<<
 
5543
 *         if c_cur == c_next or c_next[0] != c' ':
 
5544
 *             raise ValueError('Failed to parse block length')
 
5545
 */
 
5546
  __pyx_v_cur_record->block_length = strtoul(__pyx_v_c_cur, (&__pyx_v_c_next), 10);
 
5547
 
 
5548
  /* "bzrlib/_btree_serializer_pyx.pyx":760
 
5549
 *         c_cur = c_next + 1
 
5550
 *         cur_record.block_length = strtoul(c_cur, &c_next, 10)
 
5551
 *         if c_cur == c_next or c_next[0] != c' ':             # <<<<<<<<<<<<<<
 
5552
 *             raise ValueError('Failed to parse block length')
 
5553
 *         c_cur = c_next + 1
 
5554
 */
 
5555
  __pyx_t_5 = (__pyx_v_c_cur == __pyx_v_c_next);
 
5556
  if (!__pyx_t_5) {
 
5557
    __pyx_t_6 = ((__pyx_v_c_next[0]) != ' ');
 
5558
    __pyx_t_4 = __pyx_t_6;
 
5559
  } else {
 
5560
    __pyx_t_4 = __pyx_t_5;
 
5561
  }
 
5562
  if (__pyx_t_4) {
 
5563
 
 
5564
    /* "bzrlib/_btree_serializer_pyx.pyx":761
 
5565
 *         cur_record.block_length = strtoul(c_cur, &c_next, 10)
 
5566
 *         if c_cur == c_next or c_next[0] != c' ':
 
5567
 *             raise ValueError('Failed to parse block length')             # <<<<<<<<<<<<<<
 
5568
 *         c_cur = c_next + 1
 
5569
 *         cur_record.record_start = strtoul(c_cur, &c_next, 10)
 
5570
 */
 
5571
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5572
    __Pyx_GOTREF(__pyx_t_2);
 
5573
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5574
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5575
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5576
    goto __pyx_L8;
 
5577
  }
 
5578
  __pyx_L8:;
 
5579
 
 
5580
  /* "bzrlib/_btree_serializer_pyx.pyx":762
 
5581
 *         if c_cur == c_next or c_next[0] != c' ':
 
5582
 *             raise ValueError('Failed to parse block length')
 
5583
 *         c_cur = c_next + 1             # <<<<<<<<<<<<<<
 
5584
 *         cur_record.record_start = strtoul(c_cur, &c_next, 10)
 
5585
 *         if c_cur == c_next or c_next[0] != c' ':
 
5586
 */
 
5587
  __pyx_v_c_cur = (__pyx_v_c_next + 1);
 
5588
 
 
5589
  /* "bzrlib/_btree_serializer_pyx.pyx":763
 
5590
 *             raise ValueError('Failed to parse block length')
 
5591
 *         c_cur = c_next + 1
 
5592
 *         cur_record.record_start = strtoul(c_cur, &c_next, 10)             # <<<<<<<<<<<<<<
 
5593
 *         if c_cur == c_next or c_next[0] != c' ':
 
5594
 *             raise ValueError('Failed to parse block length')
 
5595
 */
 
5596
  __pyx_v_cur_record->record_start = strtoul(__pyx_v_c_cur, (&__pyx_v_c_next), 10);
 
5597
 
 
5598
  /* "bzrlib/_btree_serializer_pyx.pyx":764
 
5599
 *         c_cur = c_next + 1
 
5600
 *         cur_record.record_start = strtoul(c_cur, &c_next, 10)
 
5601
 *         if c_cur == c_next or c_next[0] != c' ':             # <<<<<<<<<<<<<<
 
5602
 *             raise ValueError('Failed to parse block length')
 
5603
 *         c_cur = c_next + 1
 
5604
 */
 
5605
  __pyx_t_4 = (__pyx_v_c_cur == __pyx_v_c_next);
 
5606
  if (!__pyx_t_4) {
 
5607
    __pyx_t_5 = ((__pyx_v_c_next[0]) != ' ');
 
5608
    __pyx_t_6 = __pyx_t_5;
 
5609
  } else {
 
5610
    __pyx_t_6 = __pyx_t_4;
 
5611
  }
 
5612
  if (__pyx_t_6) {
 
5613
 
 
5614
    /* "bzrlib/_btree_serializer_pyx.pyx":765
 
5615
 *         cur_record.record_start = strtoul(c_cur, &c_next, 10)
 
5616
 *         if c_cur == c_next or c_next[0] != c' ':
 
5617
 *             raise ValueError('Failed to parse block length')             # <<<<<<<<<<<<<<
 
5618
 *         c_cur = c_next + 1
 
5619
 *         cur_record.record_end = strtoul(c_cur, &c_next, 10)
 
5620
 */
 
5621
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5622
    __Pyx_GOTREF(__pyx_t_2);
 
5623
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5624
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5625
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5626
    goto __pyx_L9;
 
5627
  }
 
5628
  __pyx_L9:;
 
5629
 
 
5630
  /* "bzrlib/_btree_serializer_pyx.pyx":766
 
5631
 *         if c_cur == c_next or c_next[0] != c' ':
 
5632
 *             raise ValueError('Failed to parse block length')
 
5633
 *         c_cur = c_next + 1             # <<<<<<<<<<<<<<
 
5634
 *         cur_record.record_end = strtoul(c_cur, &c_next, 10)
 
5635
 *         if c_cur == c_next or c_next[0] != c'\n':
 
5636
 */
 
5637
  __pyx_v_c_cur = (__pyx_v_c_next + 1);
 
5638
 
 
5639
  /* "bzrlib/_btree_serializer_pyx.pyx":767
 
5640
 *             raise ValueError('Failed to parse block length')
 
5641
 *         c_cur = c_next + 1
 
5642
 *         cur_record.record_end = strtoul(c_cur, &c_next, 10)             # <<<<<<<<<<<<<<
 
5643
 *         if c_cur == c_next or c_next[0] != c'\n':
 
5644
 *             raise ValueError('Failed to parse record end')
 
5645
 */
 
5646
  __pyx_v_cur_record->record_end = strtoul(__pyx_v_c_cur, (&__pyx_v_c_next), 10);
 
5647
 
 
5648
  /* "bzrlib/_btree_serializer_pyx.pyx":768
 
5649
 *         c_cur = c_next + 1
 
5650
 *         cur_record.record_end = strtoul(c_cur, &c_next, 10)
 
5651
 *         if c_cur == c_next or c_next[0] != c'\n':             # <<<<<<<<<<<<<<
 
5652
 *             raise ValueError('Failed to parse record end')
 
5653
 *         c_cur = c_next + 1
 
5654
 */
 
5655
  __pyx_t_6 = (__pyx_v_c_cur == __pyx_v_c_next);
 
5656
  if (!__pyx_t_6) {
 
5657
    __pyx_t_4 = ((__pyx_v_c_next[0]) != '\n');
 
5658
    __pyx_t_5 = __pyx_t_4;
 
5659
  } else {
 
5660
    __pyx_t_5 = __pyx_t_6;
 
5661
  }
 
5662
  if (__pyx_t_5) {
 
5663
 
 
5664
    /* "bzrlib/_btree_serializer_pyx.pyx":769
 
5665
 *         cur_record.record_end = strtoul(c_cur, &c_next, 10)
 
5666
 *         if c_cur == c_next or c_next[0] != c'\n':
 
5667
 *             raise ValueError('Failed to parse record end')             # <<<<<<<<<<<<<<
 
5668
 *         c_cur = c_next + 1
 
5669
 *         return c_cur
 
5670
 */
 
5671
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5672
    __Pyx_GOTREF(__pyx_t_2);
 
5673
    __Pyx_Raise(__pyx_t_2, 0, 0);
 
5674
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
5675
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5676
    goto __pyx_L10;
 
5677
  }
 
5678
  __pyx_L10:;
 
5679
 
 
5680
  /* "bzrlib/_btree_serializer_pyx.pyx":770
 
5681
 *         if c_cur == c_next or c_next[0] != c'\n':
 
5682
 *             raise ValueError('Failed to parse record end')
 
5683
 *         c_cur = c_next + 1             # <<<<<<<<<<<<<<
 
5684
 *         return c_cur
 
5685
 * 
 
5686
 */
 
5687
  __pyx_v_c_cur = (__pyx_v_c_next + 1);
 
5688
 
 
5689
  /* "bzrlib/_btree_serializer_pyx.pyx":771
 
5690
 *             raise ValueError('Failed to parse record end')
 
5691
 *         c_cur = c_next + 1
 
5692
 *         return c_cur             # <<<<<<<<<<<<<<
 
5693
 * 
 
5694
 *     cdef int _offset_for_sha1(self, char *sha1) except -1:
 
5695
 */
 
5696
  __pyx_r = __pyx_v_c_cur;
 
5697
  goto __pyx_L0;
 
5698
 
 
5699
  __pyx_r = 0;
 
5700
  goto __pyx_L0;
 
5701
  __pyx_L1_error:;
 
5702
  __Pyx_XDECREF(__pyx_t_2);
 
5703
  __Pyx_XDECREF(__pyx_t_3);
 
5704
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._parse_one_entry");
 
5705
  __pyx_r = NULL;
 
5706
  __pyx_L0:;
 
5707
  __Pyx_RefNannyFinishContext();
 
5708
  return __pyx_r;
 
5709
}
 
5710
 
 
5711
/* "bzrlib/_btree_serializer_pyx.pyx":773
 
5712
 *         return c_cur
 
5713
 * 
 
5714
 *     cdef int _offset_for_sha1(self, char *sha1) except -1:             # <<<<<<<<<<<<<<
 
5715
 *         """Find the first interesting 8-bits of this sha1."""
 
5716
 *         cdef int this_offset
 
5717
 */
 
5718
 
 
5719
static  int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__offset_for_sha1(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self, char *__pyx_v_sha1) {
 
5720
  int __pyx_v_this_offset;
 
5721
  unsigned int __pyx_v_as_uint;
 
5722
  int __pyx_r;
 
5723
  __Pyx_RefNannySetupContext("_offset_for_sha1");
 
5724
 
 
5725
  /* "bzrlib/_btree_serializer_pyx.pyx":777
 
5726
 *         cdef int this_offset
 
5727
 *         cdef unsigned int as_uint
 
5728
 *         as_uint = _sha1_to_uint(sha1)             # <<<<<<<<<<<<<<
 
5729
 *         this_offset = (as_uint >> self.common_shift) & 0xFF
 
5730
 *         return this_offset
 
5731
 */
 
5732
  __pyx_v_as_uint = __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint(__pyx_v_sha1);
 
5733
 
 
5734
  /* "bzrlib/_btree_serializer_pyx.pyx":778
 
5735
 *         cdef unsigned int as_uint
 
5736
 *         as_uint = _sha1_to_uint(sha1)
 
5737
 *         this_offset = (as_uint >> self.common_shift) & 0xFF             # <<<<<<<<<<<<<<
 
5738
 *         return this_offset
 
5739
 * 
 
5740
 */
 
5741
  __pyx_v_this_offset = ((__pyx_v_as_uint >> __pyx_v_self->common_shift) & 0xFF);
 
5742
 
 
5743
  /* "bzrlib/_btree_serializer_pyx.pyx":779
 
5744
 *         as_uint = _sha1_to_uint(sha1)
 
5745
 *         this_offset = (as_uint >> self.common_shift) & 0xFF
 
5746
 *         return this_offset             # <<<<<<<<<<<<<<
 
5747
 * 
 
5748
 *     def _get_offset_for_sha1(self, sha1):
 
5749
 */
 
5750
  __pyx_r = __pyx_v_this_offset;
 
5751
  goto __pyx_L0;
 
5752
 
 
5753
  __pyx_r = 0;
 
5754
  __pyx_L0:;
 
5755
  __Pyx_RefNannyFinishContext();
 
5756
  return __pyx_r;
 
5757
}
 
5758
 
 
5759
/* "bzrlib/_btree_serializer_pyx.pyx":781
 
5760
 *         return this_offset
 
5761
 * 
 
5762
 *     def _get_offset_for_sha1(self, sha1):             # <<<<<<<<<<<<<<
 
5763
 *         return self._offset_for_sha1(PyString_AS_STRING(sha1))
 
5764
 * 
 
5765
 */
 
5766
 
 
5767
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8_get_offset_for_sha1(PyObject *__pyx_v_self, PyObject *__pyx_v_sha1); /*proto*/
 
5768
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8_get_offset_for_sha1(PyObject *__pyx_v_self, PyObject *__pyx_v_sha1) {
 
5769
  PyObject *__pyx_r = NULL;
 
5770
  int __pyx_t_1;
 
5771
  PyObject *__pyx_t_2 = NULL;
 
5772
  __Pyx_RefNannySetupContext("_get_offset_for_sha1");
 
5773
 
 
5774
  /* "bzrlib/_btree_serializer_pyx.pyx":782
 
5775
 * 
 
5776
 *     def _get_offset_for_sha1(self, sha1):
 
5777
 *         return self._offset_for_sha1(PyString_AS_STRING(sha1))             # <<<<<<<<<<<<<<
 
5778
 * 
 
5779
 *     cdef _compute_common(self):
 
5780
 */
 
5781
  __Pyx_XDECREF(__pyx_r);
 
5782
  __pyx_t_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_offset_for_sha1(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self), PyString_AS_STRING(__pyx_v_sha1)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5783
  __pyx_t_2 = PyInt_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5784
  __Pyx_GOTREF(__pyx_t_2);
 
5785
  __pyx_r = __pyx_t_2;
 
5786
  __pyx_t_2 = 0;
 
5787
  goto __pyx_L0;
 
5788
 
 
5789
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
5790
  goto __pyx_L0;
 
5791
  __pyx_L1_error:;
 
5792
  __Pyx_XDECREF(__pyx_t_2);
 
5793
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._get_offset_for_sha1");
 
5794
  __pyx_r = NULL;
 
5795
  __pyx_L0:;
 
5796
  __Pyx_XGIVEREF(__pyx_r);
 
5797
  __Pyx_RefNannyFinishContext();
 
5798
  return __pyx_r;
 
5799
}
 
5800
 
 
5801
/* "bzrlib/_btree_serializer_pyx.pyx":784
 
5802
 *         return self._offset_for_sha1(PyString_AS_STRING(sha1))
 
5803
 * 
 
5804
 *     cdef _compute_common(self):             # <<<<<<<<<<<<<<
 
5805
 *         cdef unsigned int first
 
5806
 *         cdef unsigned int this
 
5807
 */
 
5808
 
 
5809
static  PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__compute_common(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self) {
 
5810
  unsigned int __pyx_v_first;
 
5811
  unsigned int __pyx_v_this;
 
5812
  unsigned int __pyx_v_common_mask;
 
5813
  unsigned char __pyx_v_common_shift;
 
5814
  int __pyx_v_i;
 
5815
  int __pyx_v_offset;
 
5816
  int __pyx_v_this_offset;
 
5817
  int __pyx_v_max_offset;
 
5818
  PyObject *__pyx_r = NULL;
 
5819
  int __pyx_t_1;
 
5820
  int __pyx_t_2;
 
5821
  PyObject *__pyx_t_3 = NULL;
 
5822
  PyObject *__pyx_t_4 = NULL;
 
5823
  int __pyx_t_5;
 
5824
  int __pyx_t_6;
 
5825
  int __pyx_t_7;
 
5826
  __Pyx_RefNannySetupContext("_compute_common");
 
5827
 
 
5828
  /* "bzrlib/_btree_serializer_pyx.pyx":798
 
5829
 *         # By XORing the records together, we can determine what bits are set in
 
5830
 *         # all of them
 
5831
 *         if self.num_records < 2:             # <<<<<<<<<<<<<<
 
5832
 *             # Everything is in common if you have 0 or 1 leaves
 
5833
 *             # So we'll always just shift to the first byte
 
5834
 */
 
5835
  __pyx_t_1 = (__pyx_v_self->num_records < 2);
 
5836
  if (__pyx_t_1) {
 
5837
 
 
5838
    /* "bzrlib/_btree_serializer_pyx.pyx":801
 
5839
 *             # Everything is in common if you have 0 or 1 leaves
 
5840
 *             # So we'll always just shift to the first byte
 
5841
 *             self.common_shift = 24             # <<<<<<<<<<<<<<
 
5842
 *         else:
 
5843
 *             common_mask = 0xFFFFFFFF
 
5844
 */
 
5845
    __pyx_v_self->common_shift = 24;
 
5846
    goto __pyx_L3;
 
5847
  }
 
5848
  /*else*/ {
 
5849
 
 
5850
    /* "bzrlib/_btree_serializer_pyx.pyx":803
 
5851
 *             self.common_shift = 24
 
5852
 *         else:
 
5853
 *             common_mask = 0xFFFFFFFF             # <<<<<<<<<<<<<<
 
5854
 *             first = _sha1_to_uint(self.records[0].sha1)
 
5855
 *             for i from 0 < i < self.num_records:
 
5856
 */
 
5857
    __pyx_v_common_mask = 0xFFFFFFFF;
 
5858
 
 
5859
    /* "bzrlib/_btree_serializer_pyx.pyx":804
 
5860
 *         else:
 
5861
 *             common_mask = 0xFFFFFFFF
 
5862
 *             first = _sha1_to_uint(self.records[0].sha1)             # <<<<<<<<<<<<<<
 
5863
 *             for i from 0 < i < self.num_records:
 
5864
 *                 this = _sha1_to_uint(self.records[i].sha1)
 
5865
 */
 
5866
    __pyx_v_first = __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint((__pyx_v_self->records[0]).sha1);
 
5867
 
 
5868
    /* "bzrlib/_btree_serializer_pyx.pyx":805
 
5869
 *             common_mask = 0xFFFFFFFF
 
5870
 *             first = _sha1_to_uint(self.records[0].sha1)
 
5871
 *             for i from 0 < i < self.num_records:             # <<<<<<<<<<<<<<
 
5872
 *                 this = _sha1_to_uint(self.records[i].sha1)
 
5873
 *                 common_mask = (~(first ^ this)) & common_mask
 
5874
 */
 
5875
    __pyx_t_2 = __pyx_v_self->num_records;
 
5876
    for (__pyx_v_i = 0+1; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {
 
5877
 
 
5878
      /* "bzrlib/_btree_serializer_pyx.pyx":806
 
5879
 *             first = _sha1_to_uint(self.records[0].sha1)
 
5880
 *             for i from 0 < i < self.num_records:
 
5881
 *                 this = _sha1_to_uint(self.records[i].sha1)             # <<<<<<<<<<<<<<
 
5882
 *                 common_mask = (~(first ^ this)) & common_mask
 
5883
 *             common_shift = 24
 
5884
 */
 
5885
      __pyx_v_this = __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint((__pyx_v_self->records[__pyx_v_i]).sha1);
 
5886
 
 
5887
      /* "bzrlib/_btree_serializer_pyx.pyx":807
 
5888
 *             for i from 0 < i < self.num_records:
 
5889
 *                 this = _sha1_to_uint(self.records[i].sha1)
 
5890
 *                 common_mask = (~(first ^ this)) & common_mask             # <<<<<<<<<<<<<<
 
5891
 *             common_shift = 24
 
5892
 *             while common_mask & 0x80000000 and common_shift > 0:
 
5893
 */
 
5894
      __pyx_v_common_mask = ((~(__pyx_v_first ^ __pyx_v_this)) & __pyx_v_common_mask);
 
5895
    }
 
5896
 
 
5897
    /* "bzrlib/_btree_serializer_pyx.pyx":808
 
5898
 *                 this = _sha1_to_uint(self.records[i].sha1)
 
5899
 *                 common_mask = (~(first ^ this)) & common_mask
 
5900
 *             common_shift = 24             # <<<<<<<<<<<<<<
 
5901
 *             while common_mask & 0x80000000 and common_shift > 0:
 
5902
 *                 common_mask = common_mask << 1
 
5903
 */
 
5904
    __pyx_v_common_shift = 24;
 
5905
 
 
5906
    /* "bzrlib/_btree_serializer_pyx.pyx":809
 
5907
 *                 common_mask = (~(first ^ this)) & common_mask
 
5908
 *             common_shift = 24
 
5909
 *             while common_mask & 0x80000000 and common_shift > 0:             # <<<<<<<<<<<<<<
 
5910
 *                 common_mask = common_mask << 1
 
5911
 *                 common_shift = common_shift - 1
 
5912
 */
 
5913
    while (1) {
 
5914
      __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_common_mask); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5915
      __Pyx_GOTREF(__pyx_t_3);
 
5916
      __pyx_t_4 = PyNumber_And(__pyx_t_3, __pyx_int_2147483648); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5917
      __Pyx_GOTREF(__pyx_t_4);
 
5918
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 
5919
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
5920
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
5921
      if (__pyx_t_1) {
 
5922
        __pyx_t_5 = (__pyx_v_common_shift > 0);
 
5923
        __pyx_t_6 = __pyx_t_5;
 
5924
      } else {
 
5925
        __pyx_t_6 = __pyx_t_1;
 
5926
      }
 
5927
      if (!__pyx_t_6) break;
 
5928
 
 
5929
      /* "bzrlib/_btree_serializer_pyx.pyx":810
 
5930
 *             common_shift = 24
 
5931
 *             while common_mask & 0x80000000 and common_shift > 0:
 
5932
 *                 common_mask = common_mask << 1             # <<<<<<<<<<<<<<
 
5933
 *                 common_shift = common_shift - 1
 
5934
 *             self.common_shift = common_shift
 
5935
 */
 
5936
      __pyx_v_common_mask = (__pyx_v_common_mask << 1);
 
5937
 
 
5938
      /* "bzrlib/_btree_serializer_pyx.pyx":811
 
5939
 *             while common_mask & 0x80000000 and common_shift > 0:
 
5940
 *                 common_mask = common_mask << 1
 
5941
 *                 common_shift = common_shift - 1             # <<<<<<<<<<<<<<
 
5942
 *             self.common_shift = common_shift
 
5943
 *         offset = 0
 
5944
 */
 
5945
      __pyx_v_common_shift = (__pyx_v_common_shift - 1);
 
5946
    }
 
5947
 
 
5948
    /* "bzrlib/_btree_serializer_pyx.pyx":812
 
5949
 *                 common_mask = common_mask << 1
 
5950
 *                 common_shift = common_shift - 1
 
5951
 *             self.common_shift = common_shift             # <<<<<<<<<<<<<<
 
5952
 *         offset = 0
 
5953
 *         max_offset = self.num_records
 
5954
 */
 
5955
    __pyx_v_self->common_shift = __pyx_v_common_shift;
 
5956
  }
 
5957
  __pyx_L3:;
 
5958
 
 
5959
  /* "bzrlib/_btree_serializer_pyx.pyx":813
 
5960
 *                 common_shift = common_shift - 1
 
5961
 *             self.common_shift = common_shift
 
5962
 *         offset = 0             # <<<<<<<<<<<<<<
 
5963
 *         max_offset = self.num_records
 
5964
 *         # We cap this loop at 254 records. All the other offsets just get
 
5965
 */
 
5966
  __pyx_v_offset = 0;
 
5967
 
 
5968
  /* "bzrlib/_btree_serializer_pyx.pyx":814
 
5969
 *             self.common_shift = common_shift
 
5970
 *         offset = 0
 
5971
 *         max_offset = self.num_records             # <<<<<<<<<<<<<<
 
5972
 *         # We cap this loop at 254 records. All the other offsets just get
 
5973
 *         # filled with 0xff as the singleton saying 'too many'.
 
5974
 */
 
5975
  __pyx_v_max_offset = __pyx_v_self->num_records;
 
5976
 
 
5977
  /* "bzrlib/_btree_serializer_pyx.pyx":819
 
5978
 *         # It means that if we have >255 records we have to bisect the second
 
5979
 *         # half of the list, but this is going to be very rare in practice.
 
5980
 *         if max_offset > 255:             # <<<<<<<<<<<<<<
 
5981
 *             max_offset = 255
 
5982
 *         for i from 0 <= i < max_offset:
 
5983
 */
 
5984
  __pyx_t_6 = (__pyx_v_max_offset > 255);
 
5985
  if (__pyx_t_6) {
 
5986
 
 
5987
    /* "bzrlib/_btree_serializer_pyx.pyx":820
 
5988
 *         # half of the list, but this is going to be very rare in practice.
 
5989
 *         if max_offset > 255:
 
5990
 *             max_offset = 255             # <<<<<<<<<<<<<<
 
5991
 *         for i from 0 <= i < max_offset:
 
5992
 *             this_offset = self._offset_for_sha1(self.records[i].sha1)
 
5993
 */
 
5994
    __pyx_v_max_offset = 255;
 
5995
    goto __pyx_L8;
 
5996
  }
 
5997
  __pyx_L8:;
 
5998
 
 
5999
  /* "bzrlib/_btree_serializer_pyx.pyx":821
 
6000
 *         if max_offset > 255:
 
6001
 *             max_offset = 255
 
6002
 *         for i from 0 <= i < max_offset:             # <<<<<<<<<<<<<<
 
6003
 *             this_offset = self._offset_for_sha1(self.records[i].sha1)
 
6004
 *             while offset <= this_offset:
 
6005
 */
 
6006
  __pyx_t_2 = __pyx_v_max_offset;
 
6007
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {
 
6008
 
 
6009
    /* "bzrlib/_btree_serializer_pyx.pyx":822
 
6010
 *             max_offset = 255
 
6011
 *         for i from 0 <= i < max_offset:
 
6012
 *             this_offset = self._offset_for_sha1(self.records[i].sha1)             # <<<<<<<<<<<<<<
 
6013
 *             while offset <= this_offset:
 
6014
 *                 self.offsets[offset] = i
 
6015
 */
 
6016
    __pyx_t_7 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_offset_for_sha1(__pyx_v_self, (__pyx_v_self->records[__pyx_v_i]).sha1); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6017
    __pyx_v_this_offset = __pyx_t_7;
 
6018
 
 
6019
    /* "bzrlib/_btree_serializer_pyx.pyx":823
 
6020
 *         for i from 0 <= i < max_offset:
 
6021
 *             this_offset = self._offset_for_sha1(self.records[i].sha1)
 
6022
 *             while offset <= this_offset:             # <<<<<<<<<<<<<<
 
6023
 *                 self.offsets[offset] = i
 
6024
 *                 offset = offset + 1
 
6025
 */
 
6026
    while (1) {
 
6027
      __pyx_t_6 = (__pyx_v_offset <= __pyx_v_this_offset);
 
6028
      if (!__pyx_t_6) break;
 
6029
 
 
6030
      /* "bzrlib/_btree_serializer_pyx.pyx":824
 
6031
 *             this_offset = self._offset_for_sha1(self.records[i].sha1)
 
6032
 *             while offset <= this_offset:
 
6033
 *                 self.offsets[offset] = i             # <<<<<<<<<<<<<<
 
6034
 *                 offset = offset + 1
 
6035
 *         while offset < 257:
 
6036
 */
 
6037
      (__pyx_v_self->offsets[__pyx_v_offset]) = __pyx_v_i;
 
6038
 
 
6039
      /* "bzrlib/_btree_serializer_pyx.pyx":825
 
6040
 *             while offset <= this_offset:
 
6041
 *                 self.offsets[offset] = i
 
6042
 *                 offset = offset + 1             # <<<<<<<<<<<<<<
 
6043
 *         while offset < 257:
 
6044
 *             self.offsets[offset] = max_offset
 
6045
 */
 
6046
      __pyx_v_offset = (__pyx_v_offset + 1);
 
6047
    }
 
6048
  }
 
6049
 
 
6050
  /* "bzrlib/_btree_serializer_pyx.pyx":826
 
6051
 *                 self.offsets[offset] = i
 
6052
 *                 offset = offset + 1
 
6053
 *         while offset < 257:             # <<<<<<<<<<<<<<
 
6054
 *             self.offsets[offset] = max_offset
 
6055
 *             offset = offset + 1
 
6056
 */
 
6057
  while (1) {
 
6058
    __pyx_t_6 = (__pyx_v_offset < 257);
 
6059
    if (!__pyx_t_6) break;
 
6060
 
 
6061
    /* "bzrlib/_btree_serializer_pyx.pyx":827
 
6062
 *                 offset = offset + 1
 
6063
 *         while offset < 257:
 
6064
 *             self.offsets[offset] = max_offset             # <<<<<<<<<<<<<<
 
6065
 *             offset = offset + 1
 
6066
 * 
 
6067
 */
 
6068
    (__pyx_v_self->offsets[__pyx_v_offset]) = __pyx_v_max_offset;
 
6069
 
 
6070
    /* "bzrlib/_btree_serializer_pyx.pyx":828
 
6071
 *         while offset < 257:
 
6072
 *             self.offsets[offset] = max_offset
 
6073
 *             offset = offset + 1             # <<<<<<<<<<<<<<
 
6074
 * 
 
6075
 *     def _get_offsets(self):
 
6076
 */
 
6077
    __pyx_v_offset = (__pyx_v_offset + 1);
 
6078
  }
 
6079
 
 
6080
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
6081
  goto __pyx_L0;
 
6082
  __pyx_L1_error:;
 
6083
  __Pyx_XDECREF(__pyx_t_3);
 
6084
  __Pyx_XDECREF(__pyx_t_4);
 
6085
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._compute_common");
 
6086
  __pyx_r = 0;
 
6087
  __pyx_L0:;
 
6088
  __Pyx_XGIVEREF(__pyx_r);
 
6089
  __Pyx_RefNannyFinishContext();
 
6090
  return __pyx_r;
 
6091
}
 
6092
 
 
6093
/* "bzrlib/_btree_serializer_pyx.pyx":830
 
6094
 *             offset = offset + 1
 
6095
 * 
 
6096
 *     def _get_offsets(self):             # <<<<<<<<<<<<<<
 
6097
 *         cdef int i
 
6098
 *         result = []
 
6099
 */
 
6100
 
 
6101
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_9_get_offsets(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
 
6102
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_9_get_offsets(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
 
6103
  int __pyx_v_i;
 
6104
  PyObject *__pyx_v_result;
 
6105
  PyObject *__pyx_r = NULL;
 
6106
  PyObject *__pyx_t_1 = NULL;
 
6107
  int __pyx_t_2;
 
6108
  __Pyx_RefNannySetupContext("_get_offsets");
 
6109
  __pyx_v_result = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
 
6110
 
 
6111
  /* "bzrlib/_btree_serializer_pyx.pyx":832
 
6112
 *     def _get_offsets(self):
 
6113
 *         cdef int i
 
6114
 *         result = []             # <<<<<<<<<<<<<<
 
6115
 *         for i from 0 <= i < 257:
 
6116
 *             PyList_Append(result, self.offsets[i])
 
6117
 */
 
6118
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6119
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
6120
  __Pyx_DECREF(((PyObject *)__pyx_v_result));
 
6121
  __pyx_v_result = __pyx_t_1;
 
6122
  __pyx_t_1 = 0;
 
6123
 
 
6124
  /* "bzrlib/_btree_serializer_pyx.pyx":833
 
6125
 *         cdef int i
 
6126
 *         result = []
 
6127
 *         for i from 0 <= i < 257:             # <<<<<<<<<<<<<<
 
6128
 *             PyList_Append(result, self.offsets[i])
 
6129
 *         return result
 
6130
 */
 
6131
  for (__pyx_v_i = 0; __pyx_v_i < 257; __pyx_v_i++) {
 
6132
 
 
6133
    /* "bzrlib/_btree_serializer_pyx.pyx":834
 
6134
 *         result = []
 
6135
 *         for i from 0 <= i < 257:
 
6136
 *             PyList_Append(result, self.offsets[i])             # <<<<<<<<<<<<<<
 
6137
 *         return result
 
6138
 * 
 
6139
 */
 
6140
    __pyx_t_1 = PyInt_FromLong((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->offsets[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6141
    __Pyx_GOTREF(__pyx_t_1);
 
6142
    __pyx_t_2 = PyList_Append(((PyObject *)__pyx_v_result), __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6143
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
6144
  }
 
6145
 
 
6146
  /* "bzrlib/_btree_serializer_pyx.pyx":835
 
6147
 *         for i from 0 <= i < 257:
 
6148
 *             PyList_Append(result, self.offsets[i])
 
6149
 *         return result             # <<<<<<<<<<<<<<
 
6150
 * 
 
6151
 * 
 
6152
 */
 
6153
  __Pyx_XDECREF(__pyx_r);
 
6154
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
 
6155
  __pyx_r = ((PyObject *)__pyx_v_result);
 
6156
  goto __pyx_L0;
 
6157
 
 
6158
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
6159
  goto __pyx_L0;
 
6160
  __pyx_L1_error:;
 
6161
  __Pyx_XDECREF(__pyx_t_1);
 
6162
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._get_offsets");
 
6163
  __pyx_r = NULL;
 
6164
  __pyx_L0:;
 
6165
  __Pyx_DECREF(__pyx_v_result);
 
6166
  __Pyx_XGIVEREF(__pyx_r);
 
6167
  __Pyx_RefNannyFinishContext();
 
6168
  return __pyx_r;
 
6169
}
 
6170
 
 
6171
/* "bzrlib/_btree_serializer_pyx.pyx":522
 
6172
 * 
 
6173
 *     cdef gc_chk_sha1_record *records
 
6174
 *     cdef public object last_key             # <<<<<<<<<<<<<<
 
6175
 *     cdef gc_chk_sha1_record *last_record
 
6176
 *     cdef public int num_records
 
6177
 */
 
6178
 
 
6179
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key___get__(PyObject *__pyx_v_self); /*proto*/
 
6180
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key___get__(PyObject *__pyx_v_self) {
 
6181
  PyObject *__pyx_r = NULL;
 
6182
  __Pyx_RefNannySetupContext("__get__");
 
6183
  __Pyx_XDECREF(__pyx_r);
 
6184
  __Pyx_INCREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
6185
  __pyx_r = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key;
 
6186
  goto __pyx_L0;
 
6187
 
 
6188
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
6189
  __pyx_L0:;
 
6190
  __Pyx_XGIVEREF(__pyx_r);
 
6191
  __Pyx_RefNannyFinishContext();
 
6192
  return __pyx_r;
 
6193
}
 
6194
 
 
6195
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
 
6196
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
 
6197
  int __pyx_r;
 
6198
  __Pyx_RefNannySetupContext("__set__");
 
6199
  __Pyx_INCREF(__pyx_v_value);
 
6200
  __Pyx_GIVEREF(__pyx_v_value);
 
6201
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
6202
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
6203
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key = __pyx_v_value;
 
6204
 
 
6205
  __pyx_r = 0;
 
6206
  __Pyx_RefNannyFinishContext();
 
6207
  return __pyx_r;
 
6208
}
 
6209
 
 
6210
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key_2__del__(PyObject *__pyx_v_self); /*proto*/
 
6211
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key_2__del__(PyObject *__pyx_v_self) {
 
6212
  int __pyx_r;
 
6213
  __Pyx_RefNannySetupContext("__del__");
 
6214
  __Pyx_INCREF(Py_None);
 
6215
  __Pyx_GIVEREF(Py_None);
 
6216
  __Pyx_GOTREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
6217
  __Pyx_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
 
6218
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key = Py_None;
 
6219
 
 
6220
  __pyx_r = 0;
 
6221
  __Pyx_RefNannyFinishContext();
 
6222
  return __pyx_r;
 
6223
}
 
6224
 
 
6225
/* "bzrlib/_btree_serializer_pyx.pyx":524
 
6226
 *     cdef public object last_key
 
6227
 *     cdef gc_chk_sha1_record *last_record
 
6228
 *     cdef public int num_records             # <<<<<<<<<<<<<<
 
6229
 *     # This is the number of bits to shift to get to the interesting byte. A
 
6230
 *     # value of 24 means that the very first byte changes across all keys.
 
6231
 */
 
6232
 
 
6233
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_11num_records___get__(PyObject *__pyx_v_self); /*proto*/
 
6234
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_11num_records___get__(PyObject *__pyx_v_self) {
 
6235
  PyObject *__pyx_r = NULL;
 
6236
  PyObject *__pyx_t_1 = NULL;
 
6237
  __Pyx_RefNannySetupContext("__get__");
 
6238
  __Pyx_XDECREF(__pyx_r);
 
6239
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6240
  __Pyx_GOTREF(__pyx_t_1);
 
6241
  __pyx_r = __pyx_t_1;
 
6242
  __pyx_t_1 = 0;
 
6243
  goto __pyx_L0;
 
6244
 
 
6245
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
6246
  goto __pyx_L0;
 
6247
  __pyx_L1_error:;
 
6248
  __Pyx_XDECREF(__pyx_t_1);
 
6249
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.num_records.__get__");
 
6250
  __pyx_r = NULL;
 
6251
  __pyx_L0:;
 
6252
  __Pyx_XGIVEREF(__pyx_r);
 
6253
  __Pyx_RefNannyFinishContext();
 
6254
  return __pyx_r;
 
6255
}
 
6256
 
 
6257
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_11num_records_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
 
6258
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_11num_records_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
 
6259
  int __pyx_r;
 
6260
  int __pyx_t_1;
 
6261
  __Pyx_RefNannySetupContext("__set__");
 
6262
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6263
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records = __pyx_t_1;
 
6264
 
 
6265
  __pyx_r = 0;
 
6266
  goto __pyx_L0;
 
6267
  __pyx_L1_error:;
 
6268
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.num_records.__set__");
 
6269
  __pyx_r = -1;
 
6270
  __pyx_L0:;
 
6271
  __Pyx_RefNannyFinishContext();
 
6272
  return __pyx_r;
 
6273
}
 
6274
 
 
6275
/* "bzrlib/_btree_serializer_pyx.pyx":530
 
6276
 *     # ignore. 0 means that at least the first 3 bytes are identical, though
 
6277
 *     # that is going to be very rare
 
6278
 *     cdef public unsigned char common_shift             # <<<<<<<<<<<<<<
 
6279
 *     # This maps an interesting byte to the first record that matches.
 
6280
 *     # Equivalent to bisect.bisect_left(self.records, sha1), though only taking
 
6281
 */
 
6282
 
 
6283
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_12common_shift___get__(PyObject *__pyx_v_self); /*proto*/
 
6284
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_12common_shift___get__(PyObject *__pyx_v_self) {
 
6285
  PyObject *__pyx_r = NULL;
 
6286
  PyObject *__pyx_t_1 = NULL;
 
6287
  __Pyx_RefNannySetupContext("__get__");
 
6288
  __Pyx_XDECREF(__pyx_r);
 
6289
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->common_shift); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6290
  __Pyx_GOTREF(__pyx_t_1);
 
6291
  __pyx_r = __pyx_t_1;
 
6292
  __pyx_t_1 = 0;
 
6293
  goto __pyx_L0;
 
6294
 
 
6295
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
6296
  goto __pyx_L0;
 
6297
  __pyx_L1_error:;
 
6298
  __Pyx_XDECREF(__pyx_t_1);
 
6299
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.common_shift.__get__");
 
6300
  __pyx_r = NULL;
 
6301
  __pyx_L0:;
 
6302
  __Pyx_XGIVEREF(__pyx_r);
 
6303
  __Pyx_RefNannyFinishContext();
 
6304
  return __pyx_r;
 
6305
}
 
6306
 
 
6307
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_12common_shift_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
 
6308
static int __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_12common_shift_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
 
6309
  int __pyx_r;
 
6310
  unsigned char __pyx_t_1;
 
6311
  __Pyx_RefNannySetupContext("__set__");
 
6312
  __pyx_t_1 = __Pyx_PyInt_AsUnsignedChar(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6313
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->common_shift = __pyx_t_1;
 
6314
 
 
6315
  __pyx_r = 0;
 
6316
  goto __pyx_L0;
 
6317
  __pyx_L1_error:;
 
6318
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.common_shift.__set__");
 
6319
  __pyx_r = -1;
 
6320
  __pyx_L0:;
 
6321
  __Pyx_RefNannyFinishContext();
 
6322
  return __pyx_r;
 
6323
}
 
6324
 
 
6325
/* "bzrlib/_btree_serializer_pyx.pyx":838
 
6326
 * 
 
6327
 * 
 
6328
 * def _parse_into_chk(bytes, key_length, ref_list_length):             # <<<<<<<<<<<<<<
 
6329
 *     """Parse into a format optimized for chk records."""
 
6330
 *     assert key_length == 1
 
6331
 */
 
6332
 
 
6333
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_5_parse_into_chk(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
6334
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx_5_parse_into_chk[] = "Parse into a format optimized for chk records.";
 
6335
static PyMethodDef __pyx_mdef_6bzrlib_21_btree_serializer_pyx_5_parse_into_chk = {__Pyx_NAMESTR("_parse_into_chk"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_5_parse_into_chk, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_21_btree_serializer_pyx_5_parse_into_chk)};
 
6336
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_5_parse_into_chk(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
6337
  PyObject *__pyx_v_bytes = 0;
 
6338
  PyObject *__pyx_v_key_length = 0;
 
6339
  PyObject *__pyx_v_ref_list_length = 0;
 
6340
  PyObject *__pyx_r = NULL;
 
6341
  PyObject *__pyx_t_1 = NULL;
 
6342
  int __pyx_t_2;
 
6343
  PyObject *__pyx_t_3 = NULL;
 
6344
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__bytes,&__pyx_n_s__key_length,&__pyx_n_s__ref_list_length,0};
 
6345
  __Pyx_RefNannySetupContext("_parse_into_chk");
 
6346
  __pyx_self = __pyx_self;
 
6347
  if (unlikely(__pyx_kwds)) {
 
6348
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
 
6349
    PyObject* values[3] = {0,0,0};
 
6350
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
6351
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
 
6352
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
 
6353
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
 
6354
      case  0: break;
 
6355
      default: goto __pyx_L5_argtuple_error;
 
6356
    }
 
6357
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
6358
      case  0:
 
6359
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bytes);
 
6360
      if (likely(values[0])) kw_args--;
 
6361
      else goto __pyx_L5_argtuple_error;
 
6362
      case  1:
 
6363
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key_length);
 
6364
      if (likely(values[1])) kw_args--;
 
6365
      else {
 
6366
        __Pyx_RaiseArgtupleInvalid("_parse_into_chk", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
6367
      }
 
6368
      case  2:
 
6369
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref_list_length);
 
6370
      if (likely(values[2])) kw_args--;
 
6371
      else {
 
6372
        __Pyx_RaiseArgtupleInvalid("_parse_into_chk", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
6373
      }
 
6374
    }
 
6375
    if (unlikely(kw_args > 0)) {
 
6376
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_parse_into_chk") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
6377
    }
 
6378
    __pyx_v_bytes = values[0];
 
6379
    __pyx_v_key_length = values[1];
 
6380
    __pyx_v_ref_list_length = values[2];
 
6381
  } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
 
6382
    goto __pyx_L5_argtuple_error;
 
6383
  } else {
 
6384
    __pyx_v_bytes = PyTuple_GET_ITEM(__pyx_args, 0);
 
6385
    __pyx_v_key_length = PyTuple_GET_ITEM(__pyx_args, 1);
 
6386
    __pyx_v_ref_list_length = PyTuple_GET_ITEM(__pyx_args, 2);
 
6387
  }
 
6388
  goto __pyx_L4_argument_unpacking_done;
 
6389
  __pyx_L5_argtuple_error:;
 
6390
  __Pyx_RaiseArgtupleInvalid("_parse_into_chk", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
6391
  __pyx_L3_error:;
 
6392
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._parse_into_chk");
 
6393
  __Pyx_RefNannyFinishContext();
 
6394
  return NULL;
 
6395
  __pyx_L4_argument_unpacking_done:;
 
6396
 
 
6397
  /* "bzrlib/_btree_serializer_pyx.pyx":840
 
6398
 * def _parse_into_chk(bytes, key_length, ref_list_length):
 
6399
 *     """Parse into a format optimized for chk records."""
 
6400
 *     assert key_length == 1             # <<<<<<<<<<<<<<
 
6401
 *     assert ref_list_length == 0
 
6402
 *     return GCCHKSHA1LeafNode(bytes)
 
6403
 */
 
6404
  #ifndef CYTHON_WITHOUT_ASSERTIONS
 
6405
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_key_length, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6406
  __Pyx_GOTREF(__pyx_t_1);
 
6407
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6408
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
6409
  if (unlikely(!__pyx_t_2)) {
 
6410
    PyErr_SetNone(PyExc_AssertionError);
 
6411
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6412
  }
 
6413
  #endif
 
6414
 
 
6415
  /* "bzrlib/_btree_serializer_pyx.pyx":841
 
6416
 *     """Parse into a format optimized for chk records."""
 
6417
 *     assert key_length == 1
 
6418
 *     assert ref_list_length == 0             # <<<<<<<<<<<<<<
 
6419
 *     return GCCHKSHA1LeafNode(bytes)
 
6420
 * 
 
6421
 */
 
6422
  #ifndef CYTHON_WITHOUT_ASSERTIONS
 
6423
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_ref_list_length, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6424
  __Pyx_GOTREF(__pyx_t_1);
 
6425
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6426
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
6427
  if (unlikely(!__pyx_t_2)) {
 
6428
    PyErr_SetNone(PyExc_AssertionError);
 
6429
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6430
  }
 
6431
  #endif
 
6432
 
 
6433
  /* "bzrlib/_btree_serializer_pyx.pyx":842
 
6434
 *     assert key_length == 1
 
6435
 *     assert ref_list_length == 0
 
6436
 *     return GCCHKSHA1LeafNode(bytes)             # <<<<<<<<<<<<<<
 
6437
 * 
 
6438
 * 
 
6439
 */
 
6440
  __Pyx_XDECREF(__pyx_r);
 
6441
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6442
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
6443
  __Pyx_INCREF(__pyx_v_bytes);
 
6444
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_bytes);
 
6445
  __Pyx_GIVEREF(__pyx_v_bytes);
 
6446
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6447
  __Pyx_GOTREF(__pyx_t_3);
 
6448
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
6449
  __pyx_r = __pyx_t_3;
 
6450
  __pyx_t_3 = 0;
 
6451
  goto __pyx_L0;
 
6452
 
 
6453
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
6454
  goto __pyx_L0;
 
6455
  __pyx_L1_error:;
 
6456
  __Pyx_XDECREF(__pyx_t_1);
 
6457
  __Pyx_XDECREF(__pyx_t_3);
 
6458
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._parse_into_chk");
 
6459
  __pyx_r = NULL;
 
6460
  __pyx_L0:;
 
6461
  __Pyx_XGIVEREF(__pyx_r);
 
6462
  __Pyx_RefNannyFinishContext();
 
6463
  return __pyx_r;
 
6464
}
 
6465
 
 
6466
/* "bzrlib/_btree_serializer_pyx.pyx":845
 
6467
 * 
 
6468
 * 
 
6469
 * def _flatten_node(node, reference_lists):             # <<<<<<<<<<<<<<
 
6470
 *     """Convert a node into the serialized form.
 
6471
 * 
 
6472
 */
 
6473
 
 
6474
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_6_flatten_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 
6475
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx_6_flatten_node[] = "Convert a node into the serialized form.\n\n    :param node: A tuple representing a node:\n        (index, key_tuple, value, references)\n    :param reference_lists: Does this index have reference lists?\n    :return: (string_key, flattened)\n        string_key  The serialized key for referencing this node\n        flattened   A string with the serialized form for the contents\n    ";
 
6476
static PyMethodDef __pyx_mdef_6bzrlib_21_btree_serializer_pyx_6_flatten_node = {__Pyx_NAMESTR("_flatten_node"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_6_flatten_node, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6bzrlib_21_btree_serializer_pyx_6_flatten_node)};
 
6477
static PyObject *__pyx_pf_6bzrlib_21_btree_serializer_pyx_6_flatten_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
 
6478
  PyObject *__pyx_v_node = 0;
 
6479
  PyObject *__pyx_v_reference_lists = 0;
 
6480
  int __pyx_v_have_reference_lists;
 
6481
  Py_ssize_t __pyx_v_flat_len;
 
6482
  Py_ssize_t __pyx_v_key_len;
 
6483
  Py_ssize_t __pyx_v_node_len;
 
6484
  char *__pyx_v_value;
 
6485
  Py_ssize_t __pyx_v_value_len;
 
6486
  char *__pyx_v_out;
 
6487
  Py_ssize_t __pyx_v_refs_len;
 
6488
  Py_ssize_t __pyx_v_next_len;
 
6489
  int __pyx_v_first_ref_list;
 
6490
  int __pyx_v_first_reference;
 
6491
  int __pyx_v_i;
 
6492
  Py_ssize_t __pyx_v_ref_bit_len;
 
6493
  PyObject *__pyx_v_string_key;
 
6494
  PyObject *__pyx_v_ref_lists;
 
6495
  PyObject *__pyx_v_ref_list;
 
6496
  PyObject *__pyx_v_reference;
 
6497
  PyObject *__pyx_v_ref_bit;
 
6498
  PyObject *__pyx_v_val;
 
6499
  PyObject *__pyx_v_line;
 
6500
  PyObject *__pyx_r = NULL;
 
6501
  int __pyx_t_1;
 
6502
  int __pyx_t_2;
 
6503
  int __pyx_t_3;
 
6504
  PyObject *__pyx_t_4 = NULL;
 
6505
  PyObject *__pyx_t_5 = NULL;
 
6506
  Py_ssize_t __pyx_t_6;
 
6507
  int __pyx_t_7;
 
6508
  PyObject *__pyx_t_8 = NULL;
 
6509
  Py_ssize_t __pyx_t_9;
 
6510
  PyObject *__pyx_t_10 = NULL;
 
6511
  Py_ssize_t __pyx_t_11;
 
6512
  PyObject *__pyx_t_12 = NULL;
 
6513
  char *__pyx_t_13;
 
6514
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__node,&__pyx_n_s__reference_lists,0};
 
6515
  __Pyx_RefNannySetupContext("_flatten_node");
 
6516
  __pyx_self = __pyx_self;
 
6517
  if (unlikely(__pyx_kwds)) {
 
6518
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
 
6519
    PyObject* values[2] = {0,0};
 
6520
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
6521
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
 
6522
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
 
6523
      case  0: break;
 
6524
      default: goto __pyx_L5_argtuple_error;
 
6525
    }
 
6526
    switch (PyTuple_GET_SIZE(__pyx_args)) {
 
6527
      case  0:
 
6528
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__node);
 
6529
      if (likely(values[0])) kw_args--;
 
6530
      else goto __pyx_L5_argtuple_error;
 
6531
      case  1:
 
6532
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference_lists);
 
6533
      if (likely(values[1])) kw_args--;
 
6534
      else {
 
6535
        __Pyx_RaiseArgtupleInvalid("_flatten_node", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
6536
      }
 
6537
    }
 
6538
    if (unlikely(kw_args > 0)) {
 
6539
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_flatten_node") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
6540
    }
 
6541
    __pyx_v_node = values[0];
 
6542
    __pyx_v_reference_lists = values[1];
 
6543
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
 
6544
    goto __pyx_L5_argtuple_error;
 
6545
  } else {
 
6546
    __pyx_v_node = PyTuple_GET_ITEM(__pyx_args, 0);
 
6547
    __pyx_v_reference_lists = PyTuple_GET_ITEM(__pyx_args, 1);
 
6548
  }
 
6549
  goto __pyx_L4_argument_unpacking_done;
 
6550
  __pyx_L5_argtuple_error:;
 
6551
  __Pyx_RaiseArgtupleInvalid("_flatten_node", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
 
6552
  __pyx_L3_error:;
 
6553
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._flatten_node");
 
6554
  __Pyx_RefNannyFinishContext();
 
6555
  return NULL;
 
6556
  __pyx_L4_argument_unpacking_done:;
 
6557
  __pyx_v_string_key = Py_None; __Pyx_INCREF(Py_None);
 
6558
  __pyx_v_ref_lists = Py_None; __Pyx_INCREF(Py_None);
 
6559
  __pyx_v_ref_list = Py_None; __Pyx_INCREF(Py_None);
 
6560
  __pyx_v_reference = Py_None; __Pyx_INCREF(Py_None);
 
6561
  __pyx_v_ref_bit = Py_None; __Pyx_INCREF(Py_None);
 
6562
  __pyx_v_val = Py_None; __Pyx_INCREF(Py_None);
 
6563
  __pyx_v_line = Py_None; __Pyx_INCREF(Py_None);
 
6564
 
 
6565
  /* "bzrlib/_btree_serializer_pyx.pyx":869
 
6566
 *     cdef Py_ssize_t ref_bit_len
 
6567
 * 
 
6568
 *     if not PyTuple_CheckExact(node) and not StaticTuple_CheckExact(node):             # <<<<<<<<<<<<<<
 
6569
 *         raise TypeError('We expected a tuple() or StaticTuple() for node not: %s'
 
6570
 *             % type(node))
 
6571
 */
 
6572
  __pyx_t_1 = (!PyTuple_CheckExact(__pyx_v_node));
 
6573
  if (__pyx_t_1) {
 
6574
    __pyx_t_2 = (!StaticTuple_CheckExact(__pyx_v_node));
 
6575
    __pyx_t_3 = __pyx_t_2;
 
6576
  } else {
 
6577
    __pyx_t_3 = __pyx_t_1;
 
6578
  }
 
6579
  if (__pyx_t_3) {
 
6580
 
 
6581
    /* "bzrlib/_btree_serializer_pyx.pyx":871
 
6582
 *     if not PyTuple_CheckExact(node) and not StaticTuple_CheckExact(node):
 
6583
 *         raise TypeError('We expected a tuple() or StaticTuple() for node not: %s'
 
6584
 *             % type(node))             # <<<<<<<<<<<<<<
 
6585
 *     node_len = len(node)
 
6586
 *     have_reference_lists = reference_lists
 
6587
 */
 
6588
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_48), ((PyObject *)Py_TYPE(__pyx_v_node))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6589
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
6590
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6591
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
 
6592
    PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
 
6593
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
 
6594
    __pyx_t_4 = 0;
 
6595
    __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6596
    __Pyx_GOTREF(__pyx_t_4);
 
6597
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
 
6598
    __Pyx_Raise(__pyx_t_4, 0, 0);
 
6599
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
6600
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6601
    goto __pyx_L6;
 
6602
  }
 
6603
  __pyx_L6:;
 
6604
 
 
6605
  /* "bzrlib/_btree_serializer_pyx.pyx":872
 
6606
 *         raise TypeError('We expected a tuple() or StaticTuple() for node not: %s'
 
6607
 *             % type(node))
 
6608
 *     node_len = len(node)             # <<<<<<<<<<<<<<
 
6609
 *     have_reference_lists = reference_lists
 
6610
 *     if have_reference_lists:
 
6611
 */
 
6612
  __pyx_t_6 = PyObject_Length(__pyx_v_node); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6613
  __pyx_v_node_len = __pyx_t_6;
 
6614
 
 
6615
  /* "bzrlib/_btree_serializer_pyx.pyx":873
 
6616
 *             % type(node))
 
6617
 *     node_len = len(node)
 
6618
 *     have_reference_lists = reference_lists             # <<<<<<<<<<<<<<
 
6619
 *     if have_reference_lists:
 
6620
 *         if node_len != 4:
 
6621
 */
 
6622
  __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_reference_lists); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6623
  __pyx_v_have_reference_lists = __pyx_t_7;
 
6624
 
 
6625
  /* "bzrlib/_btree_serializer_pyx.pyx":874
 
6626
 *     node_len = len(node)
 
6627
 *     have_reference_lists = reference_lists
 
6628
 *     if have_reference_lists:             # <<<<<<<<<<<<<<
 
6629
 *         if node_len != 4:
 
6630
 *             raise ValueError('With ref_lists, we expected 4 entries not: %s'
 
6631
 */
 
6632
  if (__pyx_v_have_reference_lists) {
 
6633
 
 
6634
    /* "bzrlib/_btree_serializer_pyx.pyx":875
 
6635
 *     have_reference_lists = reference_lists
 
6636
 *     if have_reference_lists:
 
6637
 *         if node_len != 4:             # <<<<<<<<<<<<<<
 
6638
 *             raise ValueError('With ref_lists, we expected 4 entries not: %s'
 
6639
 *                 % len(node))
 
6640
 */
 
6641
    __pyx_t_3 = (__pyx_v_node_len != 4);
 
6642
    if (__pyx_t_3) {
 
6643
 
 
6644
      /* "bzrlib/_btree_serializer_pyx.pyx":877
 
6645
 *         if node_len != 4:
 
6646
 *             raise ValueError('With ref_lists, we expected 4 entries not: %s'
 
6647
 *                 % len(node))             # <<<<<<<<<<<<<<
 
6648
 *     elif node_len < 3:
 
6649
 *         raise ValueError('Without ref_lists, we need at least 3 entries not: %s'
 
6650
 */
 
6651
      __pyx_t_6 = PyObject_Length(__pyx_v_node); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6652
      __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6653
      __Pyx_GOTREF(__pyx_t_4);
 
6654
      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6655
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
 
6656
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
6657
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6658
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
6659
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_5));
 
6660
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
 
6661
      __pyx_t_5 = 0;
 
6662
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6663
      __Pyx_GOTREF(__pyx_t_5);
 
6664
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
 
6665
      __Pyx_Raise(__pyx_t_5, 0, 0);
 
6666
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
6667
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6668
      goto __pyx_L8;
 
6669
    }
 
6670
    __pyx_L8:;
 
6671
    goto __pyx_L7;
 
6672
  }
 
6673
 
 
6674
  /* "bzrlib/_btree_serializer_pyx.pyx":878
 
6675
 *             raise ValueError('With ref_lists, we expected 4 entries not: %s'
 
6676
 *                 % len(node))
 
6677
 *     elif node_len < 3:             # <<<<<<<<<<<<<<
 
6678
 *         raise ValueError('Without ref_lists, we need at least 3 entries not: %s'
 
6679
 *             % len(node))
 
6680
 */
 
6681
  __pyx_t_3 = (__pyx_v_node_len < 3);
 
6682
  if (__pyx_t_3) {
 
6683
 
 
6684
    /* "bzrlib/_btree_serializer_pyx.pyx":880
 
6685
 *     elif node_len < 3:
 
6686
 *         raise ValueError('Without ref_lists, we need at least 3 entries not: %s'
 
6687
 *             % len(node))             # <<<<<<<<<<<<<<
 
6688
 *     # TODO: We can probably do better than string.join(), namely
 
6689
 *     #       when key has only 1 item, we can just grab that string
 
6690
 */
 
6691
    __pyx_t_6 = PyObject_Length(__pyx_v_node); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6692
    __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6693
    __Pyx_GOTREF(__pyx_t_5);
 
6694
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_50), __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6695
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
6696
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
6697
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6698
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
 
6699
    PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
 
6700
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
 
6701
    __pyx_t_4 = 0;
 
6702
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6703
    __Pyx_GOTREF(__pyx_t_4);
 
6704
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
 
6705
    __Pyx_Raise(__pyx_t_4, 0, 0);
 
6706
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
6707
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6708
    goto __pyx_L7;
 
6709
  }
 
6710
  __pyx_L7:;
 
6711
 
 
6712
  /* "bzrlib/_btree_serializer_pyx.pyx":891
 
6713
 *     #       We *could* do more work on our own, and grab the actual items
 
6714
 *     #       lists. For now, just ask people to use a better compiler. :)
 
6715
 *     string_key = '\0'.join(node[1])             # <<<<<<<<<<<<<<
 
6716
 * 
 
6717
 *     # TODO: instead of using string joins, precompute the final string length,
 
6718
 */
 
6719
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_51), __pyx_n_s__join); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6720
  __Pyx_GOTREF(__pyx_t_4);
 
6721
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_node, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6722
  __Pyx_GOTREF(__pyx_t_5);
 
6723
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6724
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
 
6725
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
 
6726
  __Pyx_GIVEREF(__pyx_t_5);
 
6727
  __pyx_t_5 = 0;
 
6728
  __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6729
  __Pyx_GOTREF(__pyx_t_5);
 
6730
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
6731
  __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
 
6732
  __Pyx_DECREF(__pyx_v_string_key);
 
6733
  __pyx_v_string_key = __pyx_t_5;
 
6734
  __pyx_t_5 = 0;
 
6735
 
 
6736
  /* "bzrlib/_btree_serializer_pyx.pyx":905
 
6737
 *     # ref := BYTES (NULL BYTES)*
 
6738
 *     # value := BYTES
 
6739
 *     refs_len = 0             # <<<<<<<<<<<<<<
 
6740
 *     if have_reference_lists:
 
6741
 *         # Figure out how many bytes it will take to store the references
 
6742
 */
 
6743
  __pyx_v_refs_len = 0;
 
6744
 
 
6745
  /* "bzrlib/_btree_serializer_pyx.pyx":906
 
6746
 *     # value := BYTES
 
6747
 *     refs_len = 0
 
6748
 *     if have_reference_lists:             # <<<<<<<<<<<<<<
 
6749
 *         # Figure out how many bytes it will take to store the references
 
6750
 *         ref_lists = node[3]
 
6751
 */
 
6752
  if (__pyx_v_have_reference_lists) {
 
6753
 
 
6754
    /* "bzrlib/_btree_serializer_pyx.pyx":908
 
6755
 *     if have_reference_lists:
 
6756
 *         # Figure out how many bytes it will take to store the references
 
6757
 *         ref_lists = node[3]             # <<<<<<<<<<<<<<
 
6758
 *         next_len = len(ref_lists) # TODO: use a Py function
 
6759
 *         if next_len > 0:
 
6760
 */
 
6761
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_node, 3, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6762
    __Pyx_GOTREF(__pyx_t_5);
 
6763
    __Pyx_DECREF(__pyx_v_ref_lists);
 
6764
    __pyx_v_ref_lists = __pyx_t_5;
 
6765
    __pyx_t_5 = 0;
 
6766
 
 
6767
    /* "bzrlib/_btree_serializer_pyx.pyx":909
 
6768
 *         # Figure out how many bytes it will take to store the references
 
6769
 *         ref_lists = node[3]
 
6770
 *         next_len = len(ref_lists) # TODO: use a Py function             # <<<<<<<<<<<<<<
 
6771
 *         if next_len > 0:
 
6772
 *             # If there are no nodes, we don't need to do any work
 
6773
 */
 
6774
    __pyx_t_6 = PyObject_Length(__pyx_v_ref_lists); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6775
    __pyx_v_next_len = __pyx_t_6;
 
6776
 
 
6777
    /* "bzrlib/_btree_serializer_pyx.pyx":910
 
6778
 *         ref_lists = node[3]
 
6779
 *         next_len = len(ref_lists) # TODO: use a Py function
 
6780
 *         if next_len > 0:             # <<<<<<<<<<<<<<
 
6781
 *             # If there are no nodes, we don't need to do any work
 
6782
 *             # Otherwise we will need (len - 1) '\t' characters to separate
 
6783
 */
 
6784
    __pyx_t_3 = (__pyx_v_next_len > 0);
 
6785
    if (__pyx_t_3) {
 
6786
 
 
6787
      /* "bzrlib/_btree_serializer_pyx.pyx":914
 
6788
 *             # Otherwise we will need (len - 1) '\t' characters to separate
 
6789
 *             # the reference lists
 
6790
 *             refs_len = refs_len + (next_len - 1)             # <<<<<<<<<<<<<<
 
6791
 *             for ref_list in ref_lists:
 
6792
 *                 next_len = len(ref_list)
 
6793
 */
 
6794
      __pyx_v_refs_len = (__pyx_v_refs_len + (__pyx_v_next_len - 1));
 
6795
 
 
6796
      /* "bzrlib/_btree_serializer_pyx.pyx":915
 
6797
 *             # the reference lists
 
6798
 *             refs_len = refs_len + (next_len - 1)
 
6799
 *             for ref_list in ref_lists:             # <<<<<<<<<<<<<<
 
6800
 *                 next_len = len(ref_list)
 
6801
 *                 if next_len > 0:
 
6802
 */
 
6803
      if (PyList_CheckExact(__pyx_v_ref_lists) || PyTuple_CheckExact(__pyx_v_ref_lists)) {
 
6804
        __pyx_t_6 = 0; __pyx_t_5 = __pyx_v_ref_lists; __Pyx_INCREF(__pyx_t_5);
 
6805
      } else {
 
6806
        __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_ref_lists); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6807
        __Pyx_GOTREF(__pyx_t_5);
 
6808
      }
 
6809
      for (;;) {
 
6810
        if (likely(PyList_CheckExact(__pyx_t_5))) {
 
6811
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
 
6812
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++;
 
6813
        } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
 
6814
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
 
6815
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++;
 
6816
        } else {
 
6817
          __pyx_t_8 = PyIter_Next(__pyx_t_5);
 
6818
          if (!__pyx_t_8) {
 
6819
            if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6820
            break;
 
6821
          }
 
6822
          __Pyx_GOTREF(__pyx_t_8);
 
6823
        }
 
6824
        __Pyx_DECREF(__pyx_v_ref_list);
 
6825
        __pyx_v_ref_list = __pyx_t_8;
 
6826
        __pyx_t_8 = 0;
 
6827
 
 
6828
        /* "bzrlib/_btree_serializer_pyx.pyx":916
 
6829
 *             refs_len = refs_len + (next_len - 1)
 
6830
 *             for ref_list in ref_lists:
 
6831
 *                 next_len = len(ref_list)             # <<<<<<<<<<<<<<
 
6832
 *                 if next_len > 0:
 
6833
 *                     # We will need (len - 1) '\r' characters to separate the
 
6834
 */
 
6835
        __pyx_t_9 = PyObject_Length(__pyx_v_ref_list); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6836
        __pyx_v_next_len = __pyx_t_9;
 
6837
 
 
6838
        /* "bzrlib/_btree_serializer_pyx.pyx":917
 
6839
 *             for ref_list in ref_lists:
 
6840
 *                 next_len = len(ref_list)
 
6841
 *                 if next_len > 0:             # <<<<<<<<<<<<<<
 
6842
 *                     # We will need (len - 1) '\r' characters to separate the
 
6843
 *                     # references
 
6844
 */
 
6845
        __pyx_t_3 = (__pyx_v_next_len > 0);
 
6846
        if (__pyx_t_3) {
 
6847
 
 
6848
          /* "bzrlib/_btree_serializer_pyx.pyx":920
 
6849
 *                     # We will need (len - 1) '\r' characters to separate the
 
6850
 *                     # references
 
6851
 *                     refs_len = refs_len + (next_len - 1)             # <<<<<<<<<<<<<<
 
6852
 *                     for reference in ref_list:
 
6853
 *                         if (not PyTuple_CheckExact(reference)
 
6854
 */
 
6855
          __pyx_v_refs_len = (__pyx_v_refs_len + (__pyx_v_next_len - 1));
 
6856
 
 
6857
          /* "bzrlib/_btree_serializer_pyx.pyx":921
 
6858
 *                     # references
 
6859
 *                     refs_len = refs_len + (next_len - 1)
 
6860
 *                     for reference in ref_list:             # <<<<<<<<<<<<<<
 
6861
 *                         if (not PyTuple_CheckExact(reference)
 
6862
 *                             and not StaticTuple_CheckExact(reference)):
 
6863
 */
 
6864
          if (PyList_CheckExact(__pyx_v_ref_list) || PyTuple_CheckExact(__pyx_v_ref_list)) {
 
6865
            __pyx_t_9 = 0; __pyx_t_8 = __pyx_v_ref_list; __Pyx_INCREF(__pyx_t_8);
 
6866
          } else {
 
6867
            __pyx_t_9 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_ref_list); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6868
            __Pyx_GOTREF(__pyx_t_8);
 
6869
          }
 
6870
          for (;;) {
 
6871
            if (likely(PyList_CheckExact(__pyx_t_8))) {
 
6872
              if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_8)) break;
 
6873
              __pyx_t_4 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++;
 
6874
            } else if (likely(PyTuple_CheckExact(__pyx_t_8))) {
 
6875
              if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
 
6876
              __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++;
 
6877
            } else {
 
6878
              __pyx_t_4 = PyIter_Next(__pyx_t_8);
 
6879
              if (!__pyx_t_4) {
 
6880
                if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6881
                break;
 
6882
              }
 
6883
              __Pyx_GOTREF(__pyx_t_4);
 
6884
            }
 
6885
            __Pyx_DECREF(__pyx_v_reference);
 
6886
            __pyx_v_reference = __pyx_t_4;
 
6887
            __pyx_t_4 = 0;
 
6888
 
 
6889
            /* "bzrlib/_btree_serializer_pyx.pyx":922
 
6890
 *                     refs_len = refs_len + (next_len - 1)
 
6891
 *                     for reference in ref_list:
 
6892
 *                         if (not PyTuple_CheckExact(reference)             # <<<<<<<<<<<<<<
 
6893
 *                             and not StaticTuple_CheckExact(reference)):
 
6894
 *                             raise TypeError(
 
6895
 */
 
6896
            __pyx_t_3 = (!PyTuple_CheckExact(__pyx_v_reference));
 
6897
            if (__pyx_t_3) {
 
6898
 
 
6899
              /* "bzrlib/_btree_serializer_pyx.pyx":923
 
6900
 *                     for reference in ref_list:
 
6901
 *                         if (not PyTuple_CheckExact(reference)
 
6902
 *                             and not StaticTuple_CheckExact(reference)):             # <<<<<<<<<<<<<<
 
6903
 *                             raise TypeError(
 
6904
 *                                 'We expect references to be tuples not: %s'
 
6905
 */
 
6906
              __pyx_t_1 = (!StaticTuple_CheckExact(__pyx_v_reference));
 
6907
              __pyx_t_2 = __pyx_t_1;
 
6908
            } else {
 
6909
              __pyx_t_2 = __pyx_t_3;
 
6910
            }
 
6911
            if (__pyx_t_2) {
 
6912
 
 
6913
              /* "bzrlib/_btree_serializer_pyx.pyx":926
 
6914
 *                             raise TypeError(
 
6915
 *                                 'We expect references to be tuples not: %s'
 
6916
 *                                 % type(reference))             # <<<<<<<<<<<<<<
 
6917
 *                         next_len = len(reference)
 
6918
 *                         if next_len > 0:
 
6919
 */
 
6920
              __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_52), ((PyObject *)Py_TYPE(__pyx_v_reference))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6921
              __Pyx_GOTREF(((PyObject *)__pyx_t_4));
 
6922
              __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6923
              __Pyx_GOTREF(((PyObject *)__pyx_t_10));
 
6924
              PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_4));
 
6925
              __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
 
6926
              __pyx_t_4 = 0;
 
6927
              __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6928
              __Pyx_GOTREF(__pyx_t_4);
 
6929
              __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
 
6930
              __Pyx_Raise(__pyx_t_4, 0, 0);
 
6931
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
6932
              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6933
              goto __pyx_L16;
 
6934
            }
 
6935
            __pyx_L16:;
 
6936
 
 
6937
            /* "bzrlib/_btree_serializer_pyx.pyx":927
 
6938
 *                                 'We expect references to be tuples not: %s'
 
6939
 *                                 % type(reference))
 
6940
 *                         next_len = len(reference)             # <<<<<<<<<<<<<<
 
6941
 *                         if next_len > 0:
 
6942
 *                             # We will need (len - 1) '\x00' characters to
 
6943
 */
 
6944
            __pyx_t_11 = PyObject_Length(__pyx_v_reference); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6945
            __pyx_v_next_len = __pyx_t_11;
 
6946
 
 
6947
            /* "bzrlib/_btree_serializer_pyx.pyx":928
 
6948
 *                                 % type(reference))
 
6949
 *                         next_len = len(reference)
 
6950
 *                         if next_len > 0:             # <<<<<<<<<<<<<<
 
6951
 *                             # We will need (len - 1) '\x00' characters to
 
6952
 *                             # separate the reference key
 
6953
 */
 
6954
            __pyx_t_2 = (__pyx_v_next_len > 0);
 
6955
            if (__pyx_t_2) {
 
6956
 
 
6957
              /* "bzrlib/_btree_serializer_pyx.pyx":931
 
6958
 *                             # We will need (len - 1) '\x00' characters to
 
6959
 *                             # separate the reference key
 
6960
 *                             refs_len = refs_len + (next_len - 1)             # <<<<<<<<<<<<<<
 
6961
 *                             for ref_bit in reference:
 
6962
 *                                 if not PyString_CheckExact(ref_bit):
 
6963
 */
 
6964
              __pyx_v_refs_len = (__pyx_v_refs_len + (__pyx_v_next_len - 1));
 
6965
 
 
6966
              /* "bzrlib/_btree_serializer_pyx.pyx":932
 
6967
 *                             # separate the reference key
 
6968
 *                             refs_len = refs_len + (next_len - 1)
 
6969
 *                             for ref_bit in reference:             # <<<<<<<<<<<<<<
 
6970
 *                                 if not PyString_CheckExact(ref_bit):
 
6971
 *                                     raise TypeError('We expect reference bits'
 
6972
 */
 
6973
              if (PyList_CheckExact(__pyx_v_reference) || PyTuple_CheckExact(__pyx_v_reference)) {
 
6974
                __pyx_t_11 = 0; __pyx_t_4 = __pyx_v_reference; __Pyx_INCREF(__pyx_t_4);
 
6975
              } else {
 
6976
                __pyx_t_11 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_reference); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6977
                __Pyx_GOTREF(__pyx_t_4);
 
6978
              }
 
6979
              for (;;) {
 
6980
                if (likely(PyList_CheckExact(__pyx_t_4))) {
 
6981
                  if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_4)) break;
 
6982
                  __pyx_t_10 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_11); __Pyx_INCREF(__pyx_t_10); __pyx_t_11++;
 
6983
                } else if (likely(PyTuple_CheckExact(__pyx_t_4))) {
 
6984
                  if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
 
6985
                  __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_11); __Pyx_INCREF(__pyx_t_10); __pyx_t_11++;
 
6986
                } else {
 
6987
                  __pyx_t_10 = PyIter_Next(__pyx_t_4);
 
6988
                  if (!__pyx_t_10) {
 
6989
                    if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
6990
                    break;
 
6991
                  }
 
6992
                  __Pyx_GOTREF(__pyx_t_10);
 
6993
                }
 
6994
                __Pyx_DECREF(__pyx_v_ref_bit);
 
6995
                __pyx_v_ref_bit = __pyx_t_10;
 
6996
                __pyx_t_10 = 0;
 
6997
 
 
6998
                /* "bzrlib/_btree_serializer_pyx.pyx":933
 
6999
 *                             refs_len = refs_len + (next_len - 1)
 
7000
 *                             for ref_bit in reference:
 
7001
 *                                 if not PyString_CheckExact(ref_bit):             # <<<<<<<<<<<<<<
 
7002
 *                                     raise TypeError('We expect reference bits'
 
7003
 *                                         ' to be strings not: %s'
 
7004
 */
 
7005
                __pyx_t_2 = (!PyString_CheckExact(__pyx_v_ref_bit));
 
7006
                if (__pyx_t_2) {
 
7007
 
 
7008
                  /* "bzrlib/_btree_serializer_pyx.pyx":936
 
7009
 *                                     raise TypeError('We expect reference bits'
 
7010
 *                                         ' to be strings not: %s'
 
7011
 *                                         % type(<object>ref_bit))             # <<<<<<<<<<<<<<
 
7012
 *                                 refs_len = refs_len + PyString_GET_SIZE(ref_bit)
 
7013
 * 
 
7014
 */
 
7015
                  __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)Py_TYPE(__pyx_v_ref_bit))); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7016
                  __Pyx_GOTREF(((PyObject *)__pyx_t_10));
 
7017
                  __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7018
                  __Pyx_GOTREF(((PyObject *)__pyx_t_12));
 
7019
                  PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_10));
 
7020
                  __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
 
7021
                  __pyx_t_10 = 0;
 
7022
                  __pyx_t_10 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7023
                  __Pyx_GOTREF(__pyx_t_10);
 
7024
                  __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0;
 
7025
                  __Pyx_Raise(__pyx_t_10, 0, 0);
 
7026
                  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
 
7027
                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7028
                  goto __pyx_L20;
 
7029
                }
 
7030
                __pyx_L20:;
 
7031
 
 
7032
                /* "bzrlib/_btree_serializer_pyx.pyx":937
 
7033
 *                                         ' to be strings not: %s'
 
7034
 *                                         % type(<object>ref_bit))
 
7035
 *                                 refs_len = refs_len + PyString_GET_SIZE(ref_bit)             # <<<<<<<<<<<<<<
 
7036
 * 
 
7037
 *     # So we have the (key NULL refs NULL value LF)
 
7038
 */
 
7039
                __pyx_v_refs_len = (__pyx_v_refs_len + PyString_GET_SIZE(__pyx_v_ref_bit));
 
7040
              }
 
7041
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
7042
              goto __pyx_L17;
 
7043
            }
 
7044
            __pyx_L17:;
 
7045
          }
 
7046
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
7047
          goto __pyx_L13;
 
7048
        }
 
7049
        __pyx_L13:;
 
7050
      }
 
7051
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
7052
      goto __pyx_L10;
 
7053
    }
 
7054
    __pyx_L10:;
 
7055
    goto __pyx_L9;
 
7056
  }
 
7057
  __pyx_L9:;
 
7058
 
 
7059
  /* "bzrlib/_btree_serializer_pyx.pyx":940
 
7060
 * 
 
7061
 *     # So we have the (key NULL refs NULL value LF)
 
7062
 *     key_len = PyString_Size(string_key)             # <<<<<<<<<<<<<<
 
7063
 *     val = node[2]
 
7064
 *     if not PyString_CheckExact(val):
 
7065
 */
 
7066
  __pyx_v_key_len = PyString_Size(__pyx_v_string_key);
 
7067
 
 
7068
  /* "bzrlib/_btree_serializer_pyx.pyx":941
 
7069
 *     # So we have the (key NULL refs NULL value LF)
 
7070
 *     key_len = PyString_Size(string_key)
 
7071
 *     val = node[2]             # <<<<<<<<<<<<<<
 
7072
 *     if not PyString_CheckExact(val):
 
7073
 *         raise TypeError('Expected a plain str for value not: %s'
 
7074
 */
 
7075
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_node, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7076
  __Pyx_GOTREF(__pyx_t_5);
 
7077
  __Pyx_DECREF(__pyx_v_val);
 
7078
  __pyx_v_val = __pyx_t_5;
 
7079
  __pyx_t_5 = 0;
 
7080
 
 
7081
  /* "bzrlib/_btree_serializer_pyx.pyx":942
 
7082
 *     key_len = PyString_Size(string_key)
 
7083
 *     val = node[2]
 
7084
 *     if not PyString_CheckExact(val):             # <<<<<<<<<<<<<<
 
7085
 *         raise TypeError('Expected a plain str for value not: %s'
 
7086
 *                         % type(val))
 
7087
 */
 
7088
  __pyx_t_2 = (!PyString_CheckExact(__pyx_v_val));
 
7089
  if (__pyx_t_2) {
 
7090
 
 
7091
    /* "bzrlib/_btree_serializer_pyx.pyx":944
 
7092
 *     if not PyString_CheckExact(val):
 
7093
 *         raise TypeError('Expected a plain str for value not: %s'
 
7094
 *                         % type(val))             # <<<<<<<<<<<<<<
 
7095
 *     value = PyString_AS_STRING(val)
 
7096
 *     value_len = PyString_GET_SIZE(val)
 
7097
 */
 
7098
    __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_54), ((PyObject *)Py_TYPE(__pyx_v_val))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7099
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
 
7100
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7101
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
 
7102
    PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_5));
 
7103
    __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
 
7104
    __pyx_t_5 = 0;
 
7105
    __pyx_t_5 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7106
    __Pyx_GOTREF(__pyx_t_5);
 
7107
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
 
7108
    __Pyx_Raise(__pyx_t_5, 0, 0);
 
7109
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
7110
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7111
    goto __pyx_L21;
 
7112
  }
 
7113
  __pyx_L21:;
 
7114
 
 
7115
  /* "bzrlib/_btree_serializer_pyx.pyx":945
 
7116
 *         raise TypeError('Expected a plain str for value not: %s'
 
7117
 *                         % type(val))
 
7118
 *     value = PyString_AS_STRING(val)             # <<<<<<<<<<<<<<
 
7119
 *     value_len = PyString_GET_SIZE(val)
 
7120
 *     flat_len = (key_len + 1 + refs_len + 1 + value_len + 1)
 
7121
 */
 
7122
  __pyx_v_value = PyString_AS_STRING(__pyx_v_val);
 
7123
 
 
7124
  /* "bzrlib/_btree_serializer_pyx.pyx":946
 
7125
 *                         % type(val))
 
7126
 *     value = PyString_AS_STRING(val)
 
7127
 *     value_len = PyString_GET_SIZE(val)             # <<<<<<<<<<<<<<
 
7128
 *     flat_len = (key_len + 1 + refs_len + 1 + value_len + 1)
 
7129
 *     line = PyString_FromStringAndSize(NULL, flat_len)
 
7130
 */
 
7131
  __pyx_v_value_len = PyString_GET_SIZE(__pyx_v_val);
 
7132
 
 
7133
  /* "bzrlib/_btree_serializer_pyx.pyx":947
 
7134
 *     value = PyString_AS_STRING(val)
 
7135
 *     value_len = PyString_GET_SIZE(val)
 
7136
 *     flat_len = (key_len + 1 + refs_len + 1 + value_len + 1)             # <<<<<<<<<<<<<<
 
7137
 *     line = PyString_FromStringAndSize(NULL, flat_len)
 
7138
 *     # Get a pointer to the new buffer
 
7139
 */
 
7140
  __pyx_v_flat_len = (((((__pyx_v_key_len + 1) + __pyx_v_refs_len) + 1) + __pyx_v_value_len) + 1);
 
7141
 
 
7142
  /* "bzrlib/_btree_serializer_pyx.pyx":948
 
7143
 *     value_len = PyString_GET_SIZE(val)
 
7144
 *     flat_len = (key_len + 1 + refs_len + 1 + value_len + 1)
 
7145
 *     line = PyString_FromStringAndSize(NULL, flat_len)             # <<<<<<<<<<<<<<
 
7146
 *     # Get a pointer to the new buffer
 
7147
 *     out = PyString_AsString(line)
 
7148
 */
 
7149
  __pyx_t_5 = PyString_FromStringAndSize(NULL, __pyx_v_flat_len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7150
  __Pyx_GOTREF(__pyx_t_5);
 
7151
  __Pyx_DECREF(__pyx_v_line);
 
7152
  __pyx_v_line = __pyx_t_5;
 
7153
  __pyx_t_5 = 0;
 
7154
 
 
7155
  /* "bzrlib/_btree_serializer_pyx.pyx":950
 
7156
 *     line = PyString_FromStringAndSize(NULL, flat_len)
 
7157
 *     # Get a pointer to the new buffer
 
7158
 *     out = PyString_AsString(line)             # <<<<<<<<<<<<<<
 
7159
 *     memcpy(out, PyString_AsString(string_key), key_len)
 
7160
 *     out = out + key_len
 
7161
 */
 
7162
  __pyx_t_13 = PyString_AsString(__pyx_v_line); if (unlikely(__pyx_t_13 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7163
  __pyx_v_out = __pyx_t_13;
 
7164
 
 
7165
  /* "bzrlib/_btree_serializer_pyx.pyx":951
 
7166
 *     # Get a pointer to the new buffer
 
7167
 *     out = PyString_AsString(line)
 
7168
 *     memcpy(out, PyString_AsString(string_key), key_len)             # <<<<<<<<<<<<<<
 
7169
 *     out = out + key_len
 
7170
 *     out[0] = c'\0'
 
7171
 */
 
7172
  __pyx_t_13 = PyString_AsString(__pyx_v_string_key); if (unlikely(__pyx_t_13 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7173
  memcpy(__pyx_v_out, __pyx_t_13, __pyx_v_key_len);
 
7174
 
 
7175
  /* "bzrlib/_btree_serializer_pyx.pyx":952
 
7176
 *     out = PyString_AsString(line)
 
7177
 *     memcpy(out, PyString_AsString(string_key), key_len)
 
7178
 *     out = out + key_len             # <<<<<<<<<<<<<<
 
7179
 *     out[0] = c'\0'
 
7180
 *     out = out + 1
 
7181
 */
 
7182
  __pyx_v_out = (__pyx_v_out + __pyx_v_key_len);
 
7183
 
 
7184
  /* "bzrlib/_btree_serializer_pyx.pyx":953
 
7185
 *     memcpy(out, PyString_AsString(string_key), key_len)
 
7186
 *     out = out + key_len
 
7187
 *     out[0] = c'\0'             # <<<<<<<<<<<<<<
 
7188
 *     out = out + 1
 
7189
 *     if refs_len > 0:
 
7190
 */
 
7191
  (__pyx_v_out[0]) = '\x00';
 
7192
 
 
7193
  /* "bzrlib/_btree_serializer_pyx.pyx":954
 
7194
 *     out = out + key_len
 
7195
 *     out[0] = c'\0'
 
7196
 *     out = out + 1             # <<<<<<<<<<<<<<
 
7197
 *     if refs_len > 0:
 
7198
 *         first_ref_list = 1
 
7199
 */
 
7200
  __pyx_v_out = (__pyx_v_out + 1);
 
7201
 
 
7202
  /* "bzrlib/_btree_serializer_pyx.pyx":955
 
7203
 *     out[0] = c'\0'
 
7204
 *     out = out + 1
 
7205
 *     if refs_len > 0:             # <<<<<<<<<<<<<<
 
7206
 *         first_ref_list = 1
 
7207
 *         for ref_list in ref_lists:
 
7208
 */
 
7209
  __pyx_t_2 = (__pyx_v_refs_len > 0);
 
7210
  if (__pyx_t_2) {
 
7211
 
 
7212
    /* "bzrlib/_btree_serializer_pyx.pyx":956
 
7213
 *     out = out + 1
 
7214
 *     if refs_len > 0:
 
7215
 *         first_ref_list = 1             # <<<<<<<<<<<<<<
 
7216
 *         for ref_list in ref_lists:
 
7217
 *             if first_ref_list == 0:
 
7218
 */
 
7219
    __pyx_v_first_ref_list = 1;
 
7220
 
 
7221
    /* "bzrlib/_btree_serializer_pyx.pyx":957
 
7222
 *     if refs_len > 0:
 
7223
 *         first_ref_list = 1
 
7224
 *         for ref_list in ref_lists:             # <<<<<<<<<<<<<<
 
7225
 *             if first_ref_list == 0:
 
7226
 *                 out[0] = c'\t'
 
7227
 */
 
7228
    if (PyList_CheckExact(__pyx_v_ref_lists) || PyTuple_CheckExact(__pyx_v_ref_lists)) {
 
7229
      __pyx_t_6 = 0; __pyx_t_5 = __pyx_v_ref_lists; __Pyx_INCREF(__pyx_t_5);
 
7230
    } else {
 
7231
      __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_ref_lists); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7232
      __Pyx_GOTREF(__pyx_t_5);
 
7233
    }
 
7234
    for (;;) {
 
7235
      if (likely(PyList_CheckExact(__pyx_t_5))) {
 
7236
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
 
7237
        __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++;
 
7238
      } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
 
7239
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
 
7240
        __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++;
 
7241
      } else {
 
7242
        __pyx_t_8 = PyIter_Next(__pyx_t_5);
 
7243
        if (!__pyx_t_8) {
 
7244
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7245
          break;
 
7246
        }
 
7247
        __Pyx_GOTREF(__pyx_t_8);
 
7248
      }
 
7249
      __Pyx_DECREF(__pyx_v_ref_list);
 
7250
      __pyx_v_ref_list = __pyx_t_8;
 
7251
      __pyx_t_8 = 0;
 
7252
 
 
7253
      /* "bzrlib/_btree_serializer_pyx.pyx":958
 
7254
 *         first_ref_list = 1
 
7255
 *         for ref_list in ref_lists:
 
7256
 *             if first_ref_list == 0:             # <<<<<<<<<<<<<<
 
7257
 *                 out[0] = c'\t'
 
7258
 *                 out = out + 1
 
7259
 */
 
7260
      __pyx_t_2 = (__pyx_v_first_ref_list == 0);
 
7261
      if (__pyx_t_2) {
 
7262
 
 
7263
        /* "bzrlib/_btree_serializer_pyx.pyx":959
 
7264
 *         for ref_list in ref_lists:
 
7265
 *             if first_ref_list == 0:
 
7266
 *                 out[0] = c'\t'             # <<<<<<<<<<<<<<
 
7267
 *                 out = out + 1
 
7268
 *             first_ref_list = 0
 
7269
 */
 
7270
        (__pyx_v_out[0]) = '\t';
 
7271
 
 
7272
        /* "bzrlib/_btree_serializer_pyx.pyx":960
 
7273
 *             if first_ref_list == 0:
 
7274
 *                 out[0] = c'\t'
 
7275
 *                 out = out + 1             # <<<<<<<<<<<<<<
 
7276
 *             first_ref_list = 0
 
7277
 *             first_reference = 1
 
7278
 */
 
7279
        __pyx_v_out = (__pyx_v_out + 1);
 
7280
        goto __pyx_L25;
 
7281
      }
 
7282
      __pyx_L25:;
 
7283
 
 
7284
      /* "bzrlib/_btree_serializer_pyx.pyx":961
 
7285
 *                 out[0] = c'\t'
 
7286
 *                 out = out + 1
 
7287
 *             first_ref_list = 0             # <<<<<<<<<<<<<<
 
7288
 *             first_reference = 1
 
7289
 *             for reference in ref_list:
 
7290
 */
 
7291
      __pyx_v_first_ref_list = 0;
 
7292
 
 
7293
      /* "bzrlib/_btree_serializer_pyx.pyx":962
 
7294
 *                 out = out + 1
 
7295
 *             first_ref_list = 0
 
7296
 *             first_reference = 1             # <<<<<<<<<<<<<<
 
7297
 *             for reference in ref_list:
 
7298
 *                 if first_reference == 0:
 
7299
 */
 
7300
      __pyx_v_first_reference = 1;
 
7301
 
 
7302
      /* "bzrlib/_btree_serializer_pyx.pyx":963
 
7303
 *             first_ref_list = 0
 
7304
 *             first_reference = 1
 
7305
 *             for reference in ref_list:             # <<<<<<<<<<<<<<
 
7306
 *                 if first_reference == 0:
 
7307
 *                     out[0] = c'\r'
 
7308
 */
 
7309
      if (PyList_CheckExact(__pyx_v_ref_list) || PyTuple_CheckExact(__pyx_v_ref_list)) {
 
7310
        __pyx_t_9 = 0; __pyx_t_8 = __pyx_v_ref_list; __Pyx_INCREF(__pyx_t_8);
 
7311
      } else {
 
7312
        __pyx_t_9 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_ref_list); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7313
        __Pyx_GOTREF(__pyx_t_8);
 
7314
      }
 
7315
      for (;;) {
 
7316
        if (likely(PyList_CheckExact(__pyx_t_8))) {
 
7317
          if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_8)) break;
 
7318
          __pyx_t_4 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++;
 
7319
        } else if (likely(PyTuple_CheckExact(__pyx_t_8))) {
 
7320
          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
 
7321
          __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++;
 
7322
        } else {
 
7323
          __pyx_t_4 = PyIter_Next(__pyx_t_8);
 
7324
          if (!__pyx_t_4) {
 
7325
            if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7326
            break;
 
7327
          }
 
7328
          __Pyx_GOTREF(__pyx_t_4);
 
7329
        }
 
7330
        __Pyx_DECREF(__pyx_v_reference);
 
7331
        __pyx_v_reference = __pyx_t_4;
 
7332
        __pyx_t_4 = 0;
 
7333
 
 
7334
        /* "bzrlib/_btree_serializer_pyx.pyx":964
 
7335
 *             first_reference = 1
 
7336
 *             for reference in ref_list:
 
7337
 *                 if first_reference == 0:             # <<<<<<<<<<<<<<
 
7338
 *                     out[0] = c'\r'
 
7339
 *                     out = out + 1
 
7340
 */
 
7341
        __pyx_t_2 = (__pyx_v_first_reference == 0);
 
7342
        if (__pyx_t_2) {
 
7343
 
 
7344
          /* "bzrlib/_btree_serializer_pyx.pyx":965
 
7345
 *             for reference in ref_list:
 
7346
 *                 if first_reference == 0:
 
7347
 *                     out[0] = c'\r'             # <<<<<<<<<<<<<<
 
7348
 *                     out = out + 1
 
7349
 *                 first_reference = 0
 
7350
 */
 
7351
          (__pyx_v_out[0]) = '\r';
 
7352
 
 
7353
          /* "bzrlib/_btree_serializer_pyx.pyx":966
 
7354
 *                 if first_reference == 0:
 
7355
 *                     out[0] = c'\r'
 
7356
 *                     out = out + 1             # <<<<<<<<<<<<<<
 
7357
 *                 first_reference = 0
 
7358
 *                 next_len = len(reference)
 
7359
 */
 
7360
          __pyx_v_out = (__pyx_v_out + 1);
 
7361
          goto __pyx_L28;
 
7362
        }
 
7363
        __pyx_L28:;
 
7364
 
 
7365
        /* "bzrlib/_btree_serializer_pyx.pyx":967
 
7366
 *                     out[0] = c'\r'
 
7367
 *                     out = out + 1
 
7368
 *                 first_reference = 0             # <<<<<<<<<<<<<<
 
7369
 *                 next_len = len(reference)
 
7370
 *                 for i from 0 <= i < next_len:
 
7371
 */
 
7372
        __pyx_v_first_reference = 0;
 
7373
 
 
7374
        /* "bzrlib/_btree_serializer_pyx.pyx":968
 
7375
 *                     out = out + 1
 
7376
 *                 first_reference = 0
 
7377
 *                 next_len = len(reference)             # <<<<<<<<<<<<<<
 
7378
 *                 for i from 0 <= i < next_len:
 
7379
 *                     if i != 0:
 
7380
 */
 
7381
        __pyx_t_11 = PyObject_Length(__pyx_v_reference); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7382
        __pyx_v_next_len = __pyx_t_11;
 
7383
 
 
7384
        /* "bzrlib/_btree_serializer_pyx.pyx":969
 
7385
 *                 first_reference = 0
 
7386
 *                 next_len = len(reference)
 
7387
 *                 for i from 0 <= i < next_len:             # <<<<<<<<<<<<<<
 
7388
 *                     if i != 0:
 
7389
 *                         out[0] = c'\x00'
 
7390
 */
 
7391
        __pyx_t_11 = __pyx_v_next_len;
 
7392
        for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_11; __pyx_v_i++) {
 
7393
 
 
7394
          /* "bzrlib/_btree_serializer_pyx.pyx":970
 
7395
 *                 next_len = len(reference)
 
7396
 *                 for i from 0 <= i < next_len:
 
7397
 *                     if i != 0:             # <<<<<<<<<<<<<<
 
7398
 *                         out[0] = c'\x00'
 
7399
 *                         out = out + 1
 
7400
 */
 
7401
          __pyx_t_2 = (__pyx_v_i != 0);
 
7402
          if (__pyx_t_2) {
 
7403
 
 
7404
            /* "bzrlib/_btree_serializer_pyx.pyx":971
 
7405
 *                 for i from 0 <= i < next_len:
 
7406
 *                     if i != 0:
 
7407
 *                         out[0] = c'\x00'             # <<<<<<<<<<<<<<
 
7408
 *                         out = out + 1
 
7409
 *                     ref_bit = reference[i]
 
7410
 */
 
7411
            (__pyx_v_out[0]) = '\x00';
 
7412
 
 
7413
            /* "bzrlib/_btree_serializer_pyx.pyx":972
 
7414
 *                     if i != 0:
 
7415
 *                         out[0] = c'\x00'
 
7416
 *                         out = out + 1             # <<<<<<<<<<<<<<
 
7417
 *                     ref_bit = reference[i]
 
7418
 *                     ref_bit_len = PyString_GET_SIZE(ref_bit)
 
7419
 */
 
7420
            __pyx_v_out = (__pyx_v_out + 1);
 
7421
            goto __pyx_L31;
 
7422
          }
 
7423
          __pyx_L31:;
 
7424
 
 
7425
          /* "bzrlib/_btree_serializer_pyx.pyx":973
 
7426
 *                         out[0] = c'\x00'
 
7427
 *                         out = out + 1
 
7428
 *                     ref_bit = reference[i]             # <<<<<<<<<<<<<<
 
7429
 *                     ref_bit_len = PyString_GET_SIZE(ref_bit)
 
7430
 *                     memcpy(out, PyString_AS_STRING(ref_bit), ref_bit_len)
 
7431
 */
 
7432
          __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_reference, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7433
          __Pyx_GOTREF(__pyx_t_4);
 
7434
          __Pyx_DECREF(__pyx_v_ref_bit);
 
7435
          __pyx_v_ref_bit = __pyx_t_4;
 
7436
          __pyx_t_4 = 0;
 
7437
 
 
7438
          /* "bzrlib/_btree_serializer_pyx.pyx":974
 
7439
 *                         out = out + 1
 
7440
 *                     ref_bit = reference[i]
 
7441
 *                     ref_bit_len = PyString_GET_SIZE(ref_bit)             # <<<<<<<<<<<<<<
 
7442
 *                     memcpy(out, PyString_AS_STRING(ref_bit), ref_bit_len)
 
7443
 *                     out = out + ref_bit_len
 
7444
 */
 
7445
          __pyx_v_ref_bit_len = PyString_GET_SIZE(__pyx_v_ref_bit);
 
7446
 
 
7447
          /* "bzrlib/_btree_serializer_pyx.pyx":975
 
7448
 *                     ref_bit = reference[i]
 
7449
 *                     ref_bit_len = PyString_GET_SIZE(ref_bit)
 
7450
 *                     memcpy(out, PyString_AS_STRING(ref_bit), ref_bit_len)             # <<<<<<<<<<<<<<
 
7451
 *                     out = out + ref_bit_len
 
7452
 *     out[0] = c'\0'
 
7453
 */
 
7454
          memcpy(__pyx_v_out, PyString_AS_STRING(__pyx_v_ref_bit), __pyx_v_ref_bit_len);
 
7455
 
 
7456
          /* "bzrlib/_btree_serializer_pyx.pyx":976
 
7457
 *                     ref_bit_len = PyString_GET_SIZE(ref_bit)
 
7458
 *                     memcpy(out, PyString_AS_STRING(ref_bit), ref_bit_len)
 
7459
 *                     out = out + ref_bit_len             # <<<<<<<<<<<<<<
 
7460
 *     out[0] = c'\0'
 
7461
 *     out = out  + 1
 
7462
 */
 
7463
          __pyx_v_out = (__pyx_v_out + __pyx_v_ref_bit_len);
 
7464
        }
 
7465
      }
 
7466
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 
7467
    }
 
7468
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 
7469
    goto __pyx_L22;
 
7470
  }
 
7471
  __pyx_L22:;
 
7472
 
 
7473
  /* "bzrlib/_btree_serializer_pyx.pyx":977
 
7474
 *                     memcpy(out, PyString_AS_STRING(ref_bit), ref_bit_len)
 
7475
 *                     out = out + ref_bit_len
 
7476
 *     out[0] = c'\0'             # <<<<<<<<<<<<<<
 
7477
 *     out = out  + 1
 
7478
 *     memcpy(out, value, value_len)
 
7479
 */
 
7480
  (__pyx_v_out[0]) = '\x00';
 
7481
 
 
7482
  /* "bzrlib/_btree_serializer_pyx.pyx":978
 
7483
 *                     out = out + ref_bit_len
 
7484
 *     out[0] = c'\0'
 
7485
 *     out = out  + 1             # <<<<<<<<<<<<<<
 
7486
 *     memcpy(out, value, value_len)
 
7487
 *     out = out + value_len
 
7488
 */
 
7489
  __pyx_v_out = (__pyx_v_out + 1);
 
7490
 
 
7491
  /* "bzrlib/_btree_serializer_pyx.pyx":979
 
7492
 *     out[0] = c'\0'
 
7493
 *     out = out  + 1
 
7494
 *     memcpy(out, value, value_len)             # <<<<<<<<<<<<<<
 
7495
 *     out = out + value_len
 
7496
 *     out[0] = c'\n'
 
7497
 */
 
7498
  memcpy(__pyx_v_out, __pyx_v_value, __pyx_v_value_len);
 
7499
 
 
7500
  /* "bzrlib/_btree_serializer_pyx.pyx":980
 
7501
 *     out = out  + 1
 
7502
 *     memcpy(out, value, value_len)
 
7503
 *     out = out + value_len             # <<<<<<<<<<<<<<
 
7504
 *     out[0] = c'\n'
 
7505
 *     return string_key, line
 
7506
 */
 
7507
  __pyx_v_out = (__pyx_v_out + __pyx_v_value_len);
 
7508
 
 
7509
  /* "bzrlib/_btree_serializer_pyx.pyx":981
 
7510
 *     memcpy(out, value, value_len)
 
7511
 *     out = out + value_len
 
7512
 *     out[0] = c'\n'             # <<<<<<<<<<<<<<
 
7513
 *     return string_key, line
 
7514
 */
 
7515
  (__pyx_v_out[0]) = '\n';
 
7516
 
 
7517
  /* "bzrlib/_btree_serializer_pyx.pyx":982
 
7518
 *     out = out + value_len
 
7519
 *     out[0] = c'\n'
 
7520
 *     return string_key, line             # <<<<<<<<<<<<<<
 
7521
 */
 
7522
  __Pyx_XDECREF(__pyx_r);
 
7523
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
7524
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
 
7525
  __Pyx_INCREF(__pyx_v_string_key);
 
7526
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_string_key);
 
7527
  __Pyx_GIVEREF(__pyx_v_string_key);
 
7528
  __Pyx_INCREF(__pyx_v_line);
 
7529
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_line);
 
7530
  __Pyx_GIVEREF(__pyx_v_line);
 
7531
  __pyx_r = ((PyObject *)__pyx_t_5);
 
7532
  __pyx_t_5 = 0;
 
7533
  goto __pyx_L0;
 
7534
 
 
7535
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
 
7536
  goto __pyx_L0;
 
7537
  __pyx_L1_error:;
 
7538
  __Pyx_XDECREF(__pyx_t_4);
 
7539
  __Pyx_XDECREF(__pyx_t_5);
 
7540
  __Pyx_XDECREF(__pyx_t_8);
 
7541
  __Pyx_XDECREF(__pyx_t_10);
 
7542
  __Pyx_XDECREF(__pyx_t_12);
 
7543
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._flatten_node");
 
7544
  __pyx_r = NULL;
 
7545
  __pyx_L0:;
 
7546
  __Pyx_DECREF(__pyx_v_string_key);
 
7547
  __Pyx_DECREF(__pyx_v_ref_lists);
 
7548
  __Pyx_DECREF(__pyx_v_ref_list);
 
7549
  __Pyx_DECREF(__pyx_v_reference);
 
7550
  __Pyx_DECREF(__pyx_v_ref_bit);
 
7551
  __Pyx_DECREF(__pyx_v_val);
 
7552
  __Pyx_DECREF(__pyx_v_line);
 
7553
  __Pyx_XGIVEREF(__pyx_r);
 
7554
  __Pyx_RefNannyFinishContext();
 
7555
  return __pyx_r;
 
7556
}
 
7557
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser __pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
 
7558
 
 
7559
static PyObject *__pyx_tp_new_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyTypeObject *t, PyObject *a, PyObject *k) {
 
7560
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p;
 
7561
  PyObject *o = (*t->tp_alloc)(t, 0);
 
7562
  if (!o) return 0;
 
7563
  p = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o);
 
7564
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
 
7565
  p->bytes = Py_None; Py_INCREF(Py_None);
 
7566
  p->keys = Py_None; Py_INCREF(Py_None);
 
7567
  return o;
 
7568
}
 
7569
 
 
7570
static void __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyObject *o) {
 
7571
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o;
 
7572
  Py_XDECREF(p->bytes);
 
7573
  Py_XDECREF(p->keys);
 
7574
  (*Py_TYPE(o)->tp_free)(o);
 
7575
}
 
7576
 
 
7577
static int __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyObject *o, visitproc v, void *a) {
 
7578
  int e;
 
7579
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o;
 
7580
  if (p->bytes) {
 
7581
    e = (*v)(p->bytes, a); if (e) return e;
 
7582
  }
 
7583
  if (p->keys) {
 
7584
    e = (*v)(p->keys, a); if (e) return e;
 
7585
  }
 
7586
  return 0;
 
7587
}
 
7588
 
 
7589
static int __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyObject *o) {
 
7590
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o;
 
7591
  PyObject* tmp;
 
7592
  tmp = ((PyObject*)p->bytes);
 
7593
  p->bytes = Py_None; Py_INCREF(Py_None);
 
7594
  Py_XDECREF(tmp);
 
7595
  tmp = ((PyObject*)p->keys);
 
7596
  p->keys = Py_None; Py_INCREF(Py_None);
 
7597
  Py_XDECREF(tmp);
 
7598
  return 0;
 
7599
}
 
7600
 
 
7601
static PyMethodDef __pyx_methods_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser[] = {
 
7602
  {__Pyx_NAMESTR("parse"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_1parse, METH_NOARGS, __Pyx_DOCSTR(0)},
 
7603
  {0, 0, 0, 0}
 
7604
};
 
7605
 
 
7606
static PyNumberMethods __pyx_tp_as_number_BTreeLeafParser = {
 
7607
  0, /*nb_add*/
 
7608
  0, /*nb_subtract*/
 
7609
  0, /*nb_multiply*/
 
7610
  #if PY_MAJOR_VERSION < 3
 
7611
  0, /*nb_divide*/
 
7612
  #endif
 
7613
  0, /*nb_remainder*/
 
7614
  0, /*nb_divmod*/
 
7615
  0, /*nb_power*/
 
7616
  0, /*nb_negative*/
 
7617
  0, /*nb_positive*/
 
7618
  0, /*nb_absolute*/
 
7619
  0, /*nb_nonzero*/
 
7620
  0, /*nb_invert*/
 
7621
  0, /*nb_lshift*/
 
7622
  0, /*nb_rshift*/
 
7623
  0, /*nb_and*/
 
7624
  0, /*nb_xor*/
 
7625
  0, /*nb_or*/
 
7626
  #if PY_MAJOR_VERSION < 3
 
7627
  0, /*nb_coerce*/
 
7628
  #endif
 
7629
  0, /*nb_int*/
 
7630
  #if PY_MAJOR_VERSION < 3
 
7631
  0, /*nb_long*/
 
7632
  #else
 
7633
  0, /*reserved*/
 
7634
  #endif
 
7635
  0, /*nb_float*/
 
7636
  #if PY_MAJOR_VERSION < 3
 
7637
  0, /*nb_oct*/
 
7638
  #endif
 
7639
  #if PY_MAJOR_VERSION < 3
 
7640
  0, /*nb_hex*/
 
7641
  #endif
 
7642
  0, /*nb_inplace_add*/
 
7643
  0, /*nb_inplace_subtract*/
 
7644
  0, /*nb_inplace_multiply*/
 
7645
  #if PY_MAJOR_VERSION < 3
 
7646
  0, /*nb_inplace_divide*/
 
7647
  #endif
 
7648
  0, /*nb_inplace_remainder*/
 
7649
  0, /*nb_inplace_power*/
 
7650
  0, /*nb_inplace_lshift*/
 
7651
  0, /*nb_inplace_rshift*/
 
7652
  0, /*nb_inplace_and*/
 
7653
  0, /*nb_inplace_xor*/
 
7654
  0, /*nb_inplace_or*/
 
7655
  0, /*nb_floor_divide*/
 
7656
  0, /*nb_true_divide*/
 
7657
  0, /*nb_inplace_floor_divide*/
 
7658
  0, /*nb_inplace_true_divide*/
 
7659
  #if PY_VERSION_HEX >= 0x02050000
 
7660
  0, /*nb_index*/
 
7661
  #endif
 
7662
};
 
7663
 
 
7664
static PySequenceMethods __pyx_tp_as_sequence_BTreeLeafParser = {
 
7665
  0, /*sq_length*/
 
7666
  0, /*sq_concat*/
 
7667
  0, /*sq_repeat*/
 
7668
  0, /*sq_item*/
 
7669
  0, /*sq_slice*/
 
7670
  0, /*sq_ass_item*/
 
7671
  0, /*sq_ass_slice*/
 
7672
  0, /*sq_contains*/
 
7673
  0, /*sq_inplace_concat*/
 
7674
  0, /*sq_inplace_repeat*/
 
7675
};
 
7676
 
 
7677
static PyMappingMethods __pyx_tp_as_mapping_BTreeLeafParser = {
 
7678
  0, /*mp_length*/
 
7679
  0, /*mp_subscript*/
 
7680
  0, /*mp_ass_subscript*/
 
7681
};
 
7682
 
 
7683
static PyBufferProcs __pyx_tp_as_buffer_BTreeLeafParser = {
 
7684
  #if PY_MAJOR_VERSION < 3
 
7685
  0, /*bf_getreadbuffer*/
 
7686
  #endif
 
7687
  #if PY_MAJOR_VERSION < 3
 
7688
  0, /*bf_getwritebuffer*/
 
7689
  #endif
 
7690
  #if PY_MAJOR_VERSION < 3
 
7691
  0, /*bf_getsegcount*/
 
7692
  #endif
 
7693
  #if PY_MAJOR_VERSION < 3
 
7694
  0, /*bf_getcharbuffer*/
 
7695
  #endif
 
7696
  #if PY_VERSION_HEX >= 0x02060000
 
7697
  0, /*bf_getbuffer*/
 
7698
  #endif
 
7699
  #if PY_VERSION_HEX >= 0x02060000
 
7700
  0, /*bf_releasebuffer*/
 
7701
  #endif
 
7702
};
 
7703
 
 
7704
static PyTypeObject __pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = {
 
7705
  PyVarObject_HEAD_INIT(0, 0)
 
7706
  __Pyx_NAMESTR("bzrlib._btree_serializer_pyx.BTreeLeafParser"), /*tp_name*/
 
7707
  sizeof(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser), /*tp_basicsize*/
 
7708
  0, /*tp_itemsize*/
 
7709
  __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_dealloc*/
 
7710
  0, /*tp_print*/
 
7711
  0, /*tp_getattr*/
 
7712
  0, /*tp_setattr*/
 
7713
  #if PY_MAJOR_VERSION < 3
 
7714
  0, /*tp_compare*/
 
7715
  #else
 
7716
  0, /*reserved*/
 
7717
  #endif
 
7718
  0, /*tp_repr*/
 
7719
  &__pyx_tp_as_number_BTreeLeafParser, /*tp_as_number*/
 
7720
  &__pyx_tp_as_sequence_BTreeLeafParser, /*tp_as_sequence*/
 
7721
  &__pyx_tp_as_mapping_BTreeLeafParser, /*tp_as_mapping*/
 
7722
  0, /*tp_hash*/
 
7723
  0, /*tp_call*/
 
7724
  0, /*tp_str*/
 
7725
  0, /*tp_getattro*/
 
7726
  0, /*tp_setattro*/
 
7727
  &__pyx_tp_as_buffer_BTreeLeafParser, /*tp_as_buffer*/
 
7728
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
 
7729
  __Pyx_DOCSTR("Parse the leaf nodes of a BTree index.\n\n    :ivar bytes: The PyString object containing the uncompressed text for the\n        node.\n    :ivar key_length: An integer describing how many pieces the keys have for\n        this index.\n    :ivar ref_list_length: An integer describing how many references this index\n        contains.\n    :ivar keys: A PyList of keys found in this node.\n\n    :ivar _cur_str: A pointer to the start of the next line to parse\n    :ivar _end_str: A pointer to the end of bytes\n    :ivar _start: Pointer to the location within the current line while\n        parsing.\n    :ivar _header_found: True when we have parsed the header for this node\n    "), /*tp_doc*/
 
7730
  __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_traverse*/
 
7731
  __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_clear*/
 
7732
  0, /*tp_richcompare*/
 
7733
  0, /*tp_weaklistoffset*/
 
7734
  0, /*tp_iter*/
 
7735
  0, /*tp_iternext*/
 
7736
  __pyx_methods_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_methods*/
 
7737
  0, /*tp_members*/
 
7738
  0, /*tp_getset*/
 
7739
  0, /*tp_base*/
 
7740
  0, /*tp_dict*/
 
7741
  0, /*tp_descr_get*/
 
7742
  0, /*tp_descr_set*/
 
7743
  0, /*tp_dictoffset*/
 
7744
  __pyx_pf_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser___init__, /*tp_init*/
 
7745
  0, /*tp_alloc*/
 
7746
  __pyx_tp_new_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_new*/
 
7747
  0, /*tp_free*/
 
7748
  0, /*tp_is_gc*/
 
7749
  0, /*tp_bases*/
 
7750
  0, /*tp_mro*/
 
7751
  0, /*tp_cache*/
 
7752
  0, /*tp_subclasses*/
 
7753
  0, /*tp_weaklist*/
 
7754
  0, /*tp_del*/
 
7755
  #if PY_VERSION_HEX >= 0x02060000
 
7756
  0, /*tp_version_tag*/
 
7757
  #endif
 
7758
};
 
7759
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
 
7760
 
 
7761
static PyObject *__pyx_tp_new_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyTypeObject *t, PyObject *a, PyObject *k) {
 
7762
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p;
 
7763
  PyObject *o = (*t->tp_alloc)(t, 0);
 
7764
  if (!o) return 0;
 
7765
  p = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o);
 
7766
  p->__pyx_vtab = __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
 
7767
  p->last_key = Py_None; Py_INCREF(Py_None);
 
7768
  return o;
 
7769
}
 
7770
 
 
7771
static void __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o) {
 
7772
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o;
 
7773
  {
 
7774
    PyObject *etype, *eval, *etb;
 
7775
    PyErr_Fetch(&etype, &eval, &etb);
 
7776
    ++Py_REFCNT(o);
 
7777
    __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_1__dealloc__(o);
 
7778
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
 
7779
    --Py_REFCNT(o);
 
7780
    PyErr_Restore(etype, eval, etb);
 
7781
  }
 
7782
  Py_XDECREF(p->last_key);
 
7783
  (*Py_TYPE(o)->tp_free)(o);
 
7784
}
 
7785
 
 
7786
static int __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o, visitproc v, void *a) {
 
7787
  int e;
 
7788
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o;
 
7789
  if (p->last_key) {
 
7790
    e = (*v)(p->last_key, a); if (e) return e;
 
7791
  }
 
7792
  return 0;
 
7793
}
 
7794
 
 
7795
static int __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o) {
 
7796
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o;
 
7797
  PyObject* tmp;
 
7798
  tmp = ((PyObject*)p->last_key);
 
7799
  p->last_key = Py_None; Py_INCREF(Py_None);
 
7800
  Py_XDECREF(tmp);
 
7801
  return 0;
 
7802
}
 
7803
static PyObject *__pyx_sq_item_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o, Py_ssize_t i) {
 
7804
  PyObject *r;
 
7805
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
 
7806
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
 
7807
  Py_DECREF(x);
 
7808
  return r;
 
7809
}
 
7810
 
 
7811
static PyObject *__pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_min_key(PyObject *o, void *x) {
 
7812
  return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7min_key___get__(o);
 
7813
}
 
7814
 
 
7815
static PyObject *__pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_max_key(PyObject *o, void *x) {
 
7816
  return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7max_key___get__(o);
 
7817
}
 
7818
 
 
7819
static PyObject *__pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_last_key(PyObject *o, void *x) {
 
7820
  return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key___get__(o);
 
7821
}
 
7822
 
 
7823
static int __pyx_setprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_last_key(PyObject *o, PyObject *v, void *x) {
 
7824
  if (v) {
 
7825
    return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key_1__set__(o, v);
 
7826
  }
 
7827
  else {
 
7828
    return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8last_key_2__del__(o);
 
7829
  }
 
7830
}
 
7831
 
 
7832
static PyObject *__pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_num_records(PyObject *o, void *x) {
 
7833
  return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_11num_records___get__(o);
 
7834
}
 
7835
 
 
7836
static int __pyx_setprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_num_records(PyObject *o, PyObject *v, void *x) {
 
7837
  if (v) {
 
7838
    return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_11num_records_1__set__(o, v);
 
7839
  }
 
7840
  else {
 
7841
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
 
7842
    return -1;
 
7843
  }
 
7844
}
 
7845
 
 
7846
static PyObject *__pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_common_shift(PyObject *o, void *x) {
 
7847
  return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_12common_shift___get__(o);
 
7848
}
 
7849
 
 
7850
static int __pyx_setprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_common_shift(PyObject *o, PyObject *v, void *x) {
 
7851
  if (v) {
 
7852
    return __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_12common_shift_1__set__(o, v);
 
7853
  }
 
7854
  else {
 
7855
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
 
7856
    return -1;
 
7857
  }
 
7858
}
 
7859
 
 
7860
static PyMethodDef __pyx_methods_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode[] = {
 
7861
  {__Pyx_NAMESTR("__sizeof__"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___sizeof__, METH_NOARGS, __Pyx_DOCSTR(0)},
 
7862
  {__Pyx_NAMESTR("all_keys"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_6all_keys, METH_NOARGS, __Pyx_DOCSTR(0)},
 
7863
  {__Pyx_NAMESTR("all_items"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7all_items, METH_NOARGS, __Pyx_DOCSTR(0)},
 
7864
  {__Pyx_NAMESTR("_get_offset_for_sha1"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_8_get_offset_for_sha1, METH_O, __Pyx_DOCSTR(0)},
 
7865
  {__Pyx_NAMESTR("_get_offsets"), (PyCFunction)__pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_9_get_offsets, METH_NOARGS, __Pyx_DOCSTR(0)},
 
7866
  {0, 0, 0, 0}
 
7867
};
 
7868
 
 
7869
static struct PyGetSetDef __pyx_getsets_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode[] = {
 
7870
  {(char *)"min_key", __pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_min_key, 0, 0, 0},
 
7871
  {(char *)"max_key", __pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_max_key, 0, 0, 0},
 
7872
  {(char *)"last_key", __pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_last_key, __pyx_setprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_last_key, 0, 0},
 
7873
  {(char *)"num_records", __pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_num_records, __pyx_setprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_num_records, 0, 0},
 
7874
  {(char *)"common_shift", __pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_common_shift, __pyx_setprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_common_shift, 0, 0},
 
7875
  {0, 0, 0, 0, 0}
 
7876
};
 
7877
 
 
7878
static PyNumberMethods __pyx_tp_as_number_GCCHKSHA1LeafNode = {
 
7879
  0, /*nb_add*/
 
7880
  0, /*nb_subtract*/
 
7881
  0, /*nb_multiply*/
 
7882
  #if PY_MAJOR_VERSION < 3
 
7883
  0, /*nb_divide*/
 
7884
  #endif
 
7885
  0, /*nb_remainder*/
 
7886
  0, /*nb_divmod*/
 
7887
  0, /*nb_power*/
 
7888
  0, /*nb_negative*/
 
7889
  0, /*nb_positive*/
 
7890
  0, /*nb_absolute*/
 
7891
  0, /*nb_nonzero*/
 
7892
  0, /*nb_invert*/
 
7893
  0, /*nb_lshift*/
 
7894
  0, /*nb_rshift*/
 
7895
  0, /*nb_and*/
 
7896
  0, /*nb_xor*/
 
7897
  0, /*nb_or*/
 
7898
  #if PY_MAJOR_VERSION < 3
 
7899
  0, /*nb_coerce*/
 
7900
  #endif
 
7901
  0, /*nb_int*/
 
7902
  #if PY_MAJOR_VERSION < 3
 
7903
  0, /*nb_long*/
 
7904
  #else
 
7905
  0, /*reserved*/
 
7906
  #endif
 
7907
  0, /*nb_float*/
 
7908
  #if PY_MAJOR_VERSION < 3
 
7909
  0, /*nb_oct*/
 
7910
  #endif
 
7911
  #if PY_MAJOR_VERSION < 3
 
7912
  0, /*nb_hex*/
 
7913
  #endif
 
7914
  0, /*nb_inplace_add*/
 
7915
  0, /*nb_inplace_subtract*/
 
7916
  0, /*nb_inplace_multiply*/
 
7917
  #if PY_MAJOR_VERSION < 3
 
7918
  0, /*nb_inplace_divide*/
 
7919
  #endif
 
7920
  0, /*nb_inplace_remainder*/
 
7921
  0, /*nb_inplace_power*/
 
7922
  0, /*nb_inplace_lshift*/
 
7923
  0, /*nb_inplace_rshift*/
 
7924
  0, /*nb_inplace_and*/
 
7925
  0, /*nb_inplace_xor*/
 
7926
  0, /*nb_inplace_or*/
 
7927
  0, /*nb_floor_divide*/
 
7928
  0, /*nb_true_divide*/
 
7929
  0, /*nb_inplace_floor_divide*/
 
7930
  0, /*nb_inplace_true_divide*/
 
7931
  #if PY_VERSION_HEX >= 0x02050000
 
7932
  0, /*nb_index*/
 
7933
  #endif
 
7934
};
 
7935
 
 
7936
static PySequenceMethods __pyx_tp_as_sequence_GCCHKSHA1LeafNode = {
 
7937
  __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_5__len__, /*sq_length*/
 
7938
  0, /*sq_concat*/
 
7939
  0, /*sq_repeat*/
 
7940
  __pyx_sq_item_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*sq_item*/
 
7941
  0, /*sq_slice*/
 
7942
  0, /*sq_ass_item*/
 
7943
  0, /*sq_ass_slice*/
 
7944
  __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_3__contains__, /*sq_contains*/
 
7945
  0, /*sq_inplace_concat*/
 
7946
  0, /*sq_inplace_repeat*/
 
7947
};
 
7948
 
 
7949
static PyMappingMethods __pyx_tp_as_mapping_GCCHKSHA1LeafNode = {
 
7950
  __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_5__len__, /*mp_length*/
 
7951
  __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_4__getitem__, /*mp_subscript*/
 
7952
  0, /*mp_ass_subscript*/
 
7953
};
 
7954
 
 
7955
static PyBufferProcs __pyx_tp_as_buffer_GCCHKSHA1LeafNode = {
 
7956
  #if PY_MAJOR_VERSION < 3
 
7957
  0, /*bf_getreadbuffer*/
 
7958
  #endif
 
7959
  #if PY_MAJOR_VERSION < 3
 
7960
  0, /*bf_getwritebuffer*/
 
7961
  #endif
 
7962
  #if PY_MAJOR_VERSION < 3
 
7963
  0, /*bf_getsegcount*/
 
7964
  #endif
 
7965
  #if PY_MAJOR_VERSION < 3
 
7966
  0, /*bf_getcharbuffer*/
 
7967
  #endif
 
7968
  #if PY_VERSION_HEX >= 0x02060000
 
7969
  0, /*bf_getbuffer*/
 
7970
  #endif
 
7971
  #if PY_VERSION_HEX >= 0x02060000
 
7972
  0, /*bf_releasebuffer*/
 
7973
  #endif
 
7974
};
 
7975
 
 
7976
static PyTypeObject __pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = {
 
7977
  PyVarObject_HEAD_INIT(0, 0)
 
7978
  __Pyx_NAMESTR("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode"), /*tp_name*/
 
7979
  sizeof(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode), /*tp_basicsize*/
 
7980
  0, /*tp_itemsize*/
 
7981
  __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_dealloc*/
 
7982
  0, /*tp_print*/
 
7983
  0, /*tp_getattr*/
 
7984
  0, /*tp_setattr*/
 
7985
  #if PY_MAJOR_VERSION < 3
 
7986
  0, /*tp_compare*/
 
7987
  #else
 
7988
  0, /*reserved*/
 
7989
  #endif
 
7990
  0, /*tp_repr*/
 
7991
  &__pyx_tp_as_number_GCCHKSHA1LeafNode, /*tp_as_number*/
 
7992
  &__pyx_tp_as_sequence_GCCHKSHA1LeafNode, /*tp_as_sequence*/
 
7993
  &__pyx_tp_as_mapping_GCCHKSHA1LeafNode, /*tp_as_mapping*/
 
7994
  0, /*tp_hash*/
 
7995
  0, /*tp_call*/
 
7996
  0, /*tp_str*/
 
7997
  0, /*tp_getattro*/
 
7998
  0, /*tp_setattro*/
 
7999
  &__pyx_tp_as_buffer_GCCHKSHA1LeafNode, /*tp_as_buffer*/
 
8000
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
 
8001
  __Pyx_DOCSTR("Track all the entries for a given leaf node."), /*tp_doc*/
 
8002
  __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_traverse*/
 
8003
  __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_clear*/
 
8004
  0, /*tp_richcompare*/
 
8005
  0, /*tp_weaklistoffset*/
 
8006
  0, /*tp_iter*/
 
8007
  0, /*tp_iternext*/
 
8008
  __pyx_methods_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_methods*/
 
8009
  0, /*tp_members*/
 
8010
  __pyx_getsets_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_getset*/
 
8011
  0, /*tp_base*/
 
8012
  0, /*tp_dict*/
 
8013
  0, /*tp_descr_get*/
 
8014
  0, /*tp_descr_set*/
 
8015
  0, /*tp_dictoffset*/
 
8016
  __pyx_pf_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_2__init__, /*tp_init*/
 
8017
  0, /*tp_alloc*/
 
8018
  __pyx_tp_new_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_new*/
 
8019
  0, /*tp_free*/
 
8020
  0, /*tp_is_gc*/
 
8021
  0, /*tp_bases*/
 
8022
  0, /*tp_mro*/
 
8023
  0, /*tp_cache*/
 
8024
  0, /*tp_subclasses*/
 
8025
  0, /*tp_weaklist*/
 
8026
  0, /*tp_del*/
 
8027
  #if PY_VERSION_HEX >= 0x02060000
 
8028
  0, /*tp_version_tag*/
 
8029
  #endif
 
8030
};
 
8031
 
 
8032
static PyMethodDef __pyx_methods[] = {
 
8033
  {0, 0, 0, 0}
 
8034
};
 
8035
 
 
8036
#if PY_MAJOR_VERSION >= 3
 
8037
static struct PyModuleDef __pyx_moduledef = {
 
8038
    PyModuleDef_HEAD_INIT,
 
8039
    __Pyx_NAMESTR("_btree_serializer_pyx"),
 
8040
    __Pyx_DOCSTR(__pyx_k_55), /* m_doc */
 
8041
    -1, /* m_size */
 
8042
    __pyx_methods /* m_methods */,
 
8043
    NULL, /* m_reload */
 
8044
    NULL, /* m_traverse */
 
8045
    NULL, /* m_clear */
 
8046
    NULL /* m_free */
 
8047
};
 
8048
#endif
 
8049
 
 
8050
static __Pyx_StringTabEntry __pyx_string_tab[] = {
 
8051
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
 
8052
  {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0},
 
8053
  {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
 
8054
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
 
8055
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
 
8056
  {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
 
8057
  {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
 
8058
  {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
 
8059
  {&__pyx_n_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 1},
 
8060
  {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0},
 
8061
  {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0},
 
8062
  {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0},
 
8063
  {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0},
 
8064
  {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0},
 
8065
  {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0},
 
8066
  {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0},
 
8067
  {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0},
 
8068
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
 
8069
  {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0},
 
8070
  {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
 
8071
  {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0},
 
8072
  {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0},
 
8073
  {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0},
 
8074
  {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
 
8075
  {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0},
 
8076
  {&__pyx_kp_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 0},
 
8077
  {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0},
 
8078
  {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0},
 
8079
  {&__pyx_n_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 1},
 
8080
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
 
8081
  {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0},
 
8082
  {&__pyx_n_s__AssertionError, __pyx_k__AssertionError, sizeof(__pyx_k__AssertionError), 0, 0, 1, 1},
 
8083
  {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
 
8084
  {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
 
8085
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
 
8086
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
 
8087
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
 
8088
  {&__pyx_n_s___compute_common, __pyx_k___compute_common, sizeof(__pyx_k___compute_common), 0, 0, 1, 1},
 
8089
  {&__pyx_n_s___count_records, __pyx_k___count_records, sizeof(__pyx_k___count_records), 0, 0, 1, 1},
 
8090
  {&__pyx_n_s___cur_str, __pyx_k___cur_str, sizeof(__pyx_k___cur_str), 0, 0, 1, 1},
 
8091
  {&__pyx_n_s___end_str, __pyx_k___end_str, sizeof(__pyx_k___end_str), 0, 0, 1, 1},
 
8092
  {&__pyx_n_s___flatten_node, __pyx_k___flatten_node, sizeof(__pyx_k___flatten_node), 0, 0, 1, 1},
 
8093
  {&__pyx_n_s___header_found, __pyx_k___header_found, sizeof(__pyx_k___header_found), 0, 0, 1, 1},
 
8094
  {&__pyx_n_s___lookup_record, __pyx_k___lookup_record, sizeof(__pyx_k___lookup_record), 0, 0, 1, 1},
 
8095
  {&__pyx_n_s___offset_for_sha1, __pyx_k___offset_for_sha1, sizeof(__pyx_k___offset_for_sha1), 0, 0, 1, 1},
 
8096
  {&__pyx_n_s___parse_bytes, __pyx_k___parse_bytes, sizeof(__pyx_k___parse_bytes), 0, 0, 1, 1},
 
8097
  {&__pyx_n_s___parse_into_chk, __pyx_k___parse_into_chk, sizeof(__pyx_k___parse_into_chk), 0, 0, 1, 1},
 
8098
  {&__pyx_n_s___parse_leaf_lines, __pyx_k___parse_leaf_lines, sizeof(__pyx_k___parse_leaf_lines), 0, 0, 1, 1},
 
8099
  {&__pyx_n_s___parse_one_entry, __pyx_k___parse_one_entry, sizeof(__pyx_k___parse_one_entry), 0, 0, 1, 1},
 
8100
  {&__pyx_n_s___py_hexlify, __pyx_k___py_hexlify, sizeof(__pyx_k___py_hexlify), 0, 0, 1, 1},
 
8101
  {&__pyx_n_s___py_key_to_sha1, __pyx_k___py_key_to_sha1, sizeof(__pyx_k___py_key_to_sha1), 0, 0, 1, 1},
 
8102
  {&__pyx_n_s___py_sha1_to_key, __pyx_k___py_sha1_to_key, sizeof(__pyx_k___py_sha1_to_key), 0, 0, 1, 1},
 
8103
  {&__pyx_n_s___py_unhexlify, __pyx_k___py_unhexlify, sizeof(__pyx_k___py_unhexlify), 0, 0, 1, 1},
 
8104
  {&__pyx_n_s___record_to_item, __pyx_k___record_to_item, sizeof(__pyx_k___record_to_item), 0, 0, 1, 1},
 
8105
  {&__pyx_n_s___start, __pyx_k___start, sizeof(__pyx_k___start), 0, 0, 1, 1},
 
8106
  {&__pyx_n_s__block_length, __pyx_k__block_length, sizeof(__pyx_k__block_length), 0, 0, 1, 1},
 
8107
  {&__pyx_n_s__block_offset, __pyx_k__block_offset, sizeof(__pyx_k__block_offset), 0, 0, 1, 1},
 
8108
  {&__pyx_n_s__bytes, __pyx_k__bytes, sizeof(__pyx_k__bytes), 0, 0, 1, 1},
 
8109
  {&__pyx_n_s__common_shift, __pyx_k__common_shift, sizeof(__pyx_k__common_shift), 0, 0, 1, 1},
 
8110
  {&__pyx_n_s__extract_key, __pyx_k__extract_key, sizeof(__pyx_k__extract_key), 0, 0, 1, 1},
 
8111
  {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1},
 
8112
  {&__pyx_n_s__key_length, __pyx_k__key_length, sizeof(__pyx_k__key_length), 0, 0, 1, 1},
 
8113
  {&__pyx_n_s__keys, __pyx_k__keys, sizeof(__pyx_k__keys), 0, 0, 1, 1},
 
8114
  {&__pyx_n_s__last_key, __pyx_k__last_key, sizeof(__pyx_k__last_key), 0, 0, 1, 1},
 
8115
  {&__pyx_n_s__last_record, __pyx_k__last_record, sizeof(__pyx_k__last_record), 0, 0, 1, 1},
 
8116
  {&__pyx_n_s__node, __pyx_k__node, sizeof(__pyx_k__node), 0, 0, 1, 1},
 
8117
  {&__pyx_n_s__num_records, __pyx_k__num_records, sizeof(__pyx_k__num_records), 0, 0, 1, 1},
 
8118
  {&__pyx_n_s__offsets, __pyx_k__offsets, sizeof(__pyx_k__offsets), 0, 0, 1, 1},
 
8119
  {&__pyx_n_s__parse, __pyx_k__parse, sizeof(__pyx_k__parse), 0, 0, 1, 1},
 
8120
  {&__pyx_n_s__process_line, __pyx_k__process_line, sizeof(__pyx_k__process_line), 0, 0, 1, 1},
 
8121
  {&__pyx_n_s__record_end, __pyx_k__record_end, sizeof(__pyx_k__record_end), 0, 0, 1, 1},
 
8122
  {&__pyx_n_s__record_start, __pyx_k__record_start, sizeof(__pyx_k__record_start), 0, 0, 1, 1},
 
8123
  {&__pyx_n_s__records, __pyx_k__records, sizeof(__pyx_k__records), 0, 0, 1, 1},
 
8124
  {&__pyx_n_s__ref_list_length, __pyx_k__ref_list_length, sizeof(__pyx_k__ref_list_length), 0, 0, 1, 1},
 
8125
  {&__pyx_n_s__reference_lists, __pyx_k__reference_lists, sizeof(__pyx_k__reference_lists), 0, 0, 1, 1},
 
8126
  {&__pyx_n_s__sha1, __pyx_k__sha1, sizeof(__pyx_k__sha1), 0, 0, 1, 1},
 
8127
  {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
 
8128
  {0, 0, 0, 0, 0, 0, 0}
 
8129
};
 
8130
static int __Pyx_InitCachedBuiltins(void) {
 
8131
  __pyx_builtin_AssertionError = __Pyx_GetName(__pyx_b, __pyx_n_s__AssertionError); if (!__pyx_builtin_AssertionError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8132
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8133
  __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8134
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8135
  return 0;
 
8136
  __pyx_L1_error:;
 
8137
  return -1;
 
8138
}
 
8139
 
 
8140
static int __Pyx_InitCachedConstants(void) {
 
8141
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
 
8142
 
 
8143
  /* "bzrlib/_btree_serializer_pyx.pyx":229
 
8144
 *         if last < self._start:
 
8145
 *             # Unexpected error condition - fail
 
8146
 *             raise AssertionError("last < self._start")             # <<<<<<<<<<<<<<
 
8147
 *         if 0 == self._header_found:
 
8148
 *             # The first line in a leaf node is the header "type=leaf\n"
 
8149
 */
 
8150
  __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8151
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_5));
 
8152
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_4));
 
8153
  PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_4));
 
8154
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4));
 
8155
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
 
8156
 
 
8157
  /* "bzrlib/_btree_serializer_pyx.pyx":244
 
8158
 *         if temp_ptr == NULL:
 
8159
 *             # Invalid line
 
8160
 *             raise AssertionError("Failed to find the value area")             # <<<<<<<<<<<<<<
 
8161
 *         else:
 
8162
 *             # Because of how conversions were done, we ended up with *lots* of
 
8163
 */
 
8164
  __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8165
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_9));
 
8166
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_8));
 
8167
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_kp_s_8));
 
8168
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_8));
 
8169
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9));
 
8170
 
 
8171
  /* "bzrlib/_btree_serializer_pyx.pyx":271
 
8172
 *                 loop_counter = loop_counter + 1
 
8173
 *                 if last < self._start:
 
8174
 *                     raise AssertionError("last < self._start")             # <<<<<<<<<<<<<<
 
8175
 *                 # find the next reference list end point:
 
8176
 *                 temp_ptr = <char*>memchr(self._start, c'\t', last - self._start)
 
8177
 */
 
8178
  __pyx_k_tuple_11 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8179
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_11));
 
8180
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_4));
 
8181
  PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, ((PyObject *)__pyx_kp_s_4));
 
8182
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4));
 
8183
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));
 
8184
 
 
8185
  /* "bzrlib/_btree_serializer_pyx.pyx":278
 
8186
 *                     if loop_counter != self.ref_list_length:
 
8187
 *                         # Invalid line
 
8188
 *                         raise AssertionError(             # <<<<<<<<<<<<<<
 
8189
 *                             "invalid key, loop_counter != self.ref_list_length")
 
8190
 *                     else:
 
8191
 */
 
8192
  __pyx_k_tuple_13 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8193
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_13));
 
8194
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_12));
 
8195
  PyTuple_SET_ITEM(__pyx_k_tuple_13, 0, ((PyObject *)__pyx_kp_s_12));
 
8196
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_12));
 
8197
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_13));
 
8198
 
 
8199
  /* "bzrlib/_btree_serializer_pyx.pyx":307
 
8200
 *             if last != self._start:
 
8201
 *                 # unexpected reference data present
 
8202
 *                 raise AssertionError("unexpected reference data present")             # <<<<<<<<<<<<<<
 
8203
 *             node_value = StaticTuple(value, StaticTuple())
 
8204
 *         PyList_Append(self.keys, StaticTuple(key, node_value))
 
8205
 */
 
8206
  __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8207
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_15));
 
8208
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_14));
 
8209
  PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14));
 
8210
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14));
 
8211
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15));
 
8212
 
 
8213
  /* "bzrlib/_btree_serializer_pyx.pyx":315
 
8214
 *         cdef Py_ssize_t byte_count
 
8215
 *         if not PyString_CheckExact(self.bytes):
 
8216
 *             raise AssertionError('self.bytes is not a string.')             # <<<<<<<<<<<<<<
 
8217
 *         byte_count = PyString_Size(self.bytes)
 
8218
 *         self._cur_str = PyString_AsString(self.bytes)
 
8219
 */
 
8220
  __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8221
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_17));
 
8222
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
 
8223
  PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_kp_s_16));
 
8224
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
 
8225
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17));
 
8226
 
 
8227
  /* "bzrlib/_btree_serializer_pyx.pyx":389
 
8228
 *     """For the test infrastructure, just thunks to _unhexlify_sha1"""
 
8229
 *     if len(as_hex) != 40 or not PyString_CheckExact(as_hex):
 
8230
 *         raise ValueError('not a 40-byte hex digest')             # <<<<<<<<<<<<<<
 
8231
 *     as_bin = PyString_FromStringAndSize(NULL, 20)
 
8232
 *     if _unhexlify_sha1(PyString_AS_STRING(as_hex), PyString_AS_STRING(as_bin)):
 
8233
 */
 
8234
  __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8235
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_19));
 
8236
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_18));
 
8237
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_18));
 
8238
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18));
 
8239
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19));
 
8240
 
 
8241
  /* "bzrlib/_btree_serializer_pyx.pyx":412
 
8242
 *     """For test infrastructure, thunk to _hexlify_sha1"""
 
8243
 *     if len(as_bin) != 20 or not PyString_CheckExact(as_bin):
 
8244
 *         raise ValueError('not a 20-byte binary digest')             # <<<<<<<<<<<<<<
 
8245
 *     as_hex = PyString_FromStringAndSize(NULL, 40)
 
8246
 *     _hexlify_sha1(PyString_AS_STRING(as_bin), PyString_AS_STRING(as_hex))
 
8247
 */
 
8248
  __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8249
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_21));
 
8250
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_20));
 
8251
  PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_20));
 
8252
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20));
 
8253
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21));
 
8254
 
 
8255
  /* "bzrlib/_btree_serializer_pyx.pyx":485
 
8256
 *     """Test thunk to check the sha1 mapping."""
 
8257
 *     if not PyString_CheckExact(sha1_bin) or PyString_GET_SIZE(sha1_bin) != 20:
 
8258
 *         raise ValueError('sha1_bin must be a str of exactly 20 bytes')             # <<<<<<<<<<<<<<
 
8259
 *     return _sha1_to_key(PyString_AS_STRING(sha1_bin))
 
8260
 * 
 
8261
 */
 
8262
  __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8263
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_23));
 
8264
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
 
8265
  PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_22));
 
8266
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
 
8267
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));
 
8268
 
 
8269
  /* "bzrlib/_btree_serializer_pyx.pyx":708
 
8270
 * 
 
8271
 *         if not PyString_CheckExact(bytes):
 
8272
 *             raise TypeError('We only support parsing plain 8-bit strings.')             # <<<<<<<<<<<<<<
 
8273
 *         # Pass 1, count how many records there will be
 
8274
 *         n_bytes = PyString_GET_SIZE(bytes)
 
8275
 */
 
8276
  __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8277
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_29));
 
8278
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_28));
 
8279
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_28));
 
8280
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28));
 
8281
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29));
 
8282
 
 
8283
  /* "bzrlib/_btree_serializer_pyx.pyx":731
 
8284
 *             or c_cur != c_end
 
8285
 *             or cur_record != self.records + self.num_records):
 
8286
 *             raise ValueError('Something went wrong while parsing.')             # <<<<<<<<<<<<<<
 
8287
 *         # Pass 3: build the offset map
 
8288
 *         self._compute_common()
 
8289
 */
 
8290
  __pyx_k_tuple_33 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8291
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_33));
 
8292
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_32));
 
8293
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_kp_s_32));
 
8294
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_32));
 
8295
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33));
 
8296
 
 
8297
  /* "bzrlib/_btree_serializer_pyx.pyx":748
 
8298
 *         c_next = <char *>memchr(c_cur, c'\0', c_end - c_cur)
 
8299
 *         if c_next == NULL or (c_next - c_cur != 40):
 
8300
 *             raise ValueError('Line did not contain 40 hex bytes')             # <<<<<<<<<<<<<<
 
8301
 *         if not _unhexlify_sha1(c_cur, cur_record.sha1):
 
8302
 *             raise ValueError('We failed to unhexlify')
 
8303
 */
 
8304
  __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8305
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_36));
 
8306
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_35));
 
8307
  PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_35));
 
8308
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_35));
 
8309
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36));
 
8310
 
 
8311
  /* "bzrlib/_btree_serializer_pyx.pyx":750
 
8312
 *             raise ValueError('Line did not contain 40 hex bytes')
 
8313
 *         if not _unhexlify_sha1(c_cur, cur_record.sha1):
 
8314
 *             raise ValueError('We failed to unhexlify')             # <<<<<<<<<<<<<<
 
8315
 *         c_cur = c_next + 1
 
8316
 *         if c_cur[0] != c'\0':
 
8317
 */
 
8318
  __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8319
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_38));
 
8320
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_37));
 
8321
  PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, ((PyObject *)__pyx_kp_s_37));
 
8322
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_37));
 
8323
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38));
 
8324
 
 
8325
  /* "bzrlib/_btree_serializer_pyx.pyx":753
 
8326
 *         c_cur = c_next + 1
 
8327
 *         if c_cur[0] != c'\0':
 
8328
 *             raise ValueError('only 1 null, not 2 as expected')             # <<<<<<<<<<<<<<
 
8329
 *         c_cur = c_cur + 1
 
8330
 *         cur_record.block_offset = strtoll(c_cur, &c_next, 10)
 
8331
 */
 
8332
  __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8333
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_40));
 
8334
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_39));
 
8335
  PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_kp_s_39));
 
8336
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_39));
 
8337
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40));
 
8338
 
 
8339
  /* "bzrlib/_btree_serializer_pyx.pyx":757
 
8340
 *         cur_record.block_offset = strtoll(c_cur, &c_next, 10)
 
8341
 *         if c_cur == c_next or c_next[0] != c' ':
 
8342
 *             raise ValueError('Failed to parse block offset')             # <<<<<<<<<<<<<<
 
8343
 *         c_cur = c_next + 1
 
8344
 *         cur_record.block_length = strtoul(c_cur, &c_next, 10)
 
8345
 */
 
8346
  __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8347
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_42));
 
8348
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_41));
 
8349
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_kp_s_41));
 
8350
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41));
 
8351
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42));
 
8352
 
 
8353
  /* "bzrlib/_btree_serializer_pyx.pyx":761
 
8354
 *         cur_record.block_length = strtoul(c_cur, &c_next, 10)
 
8355
 *         if c_cur == c_next or c_next[0] != c' ':
 
8356
 *             raise ValueError('Failed to parse block length')             # <<<<<<<<<<<<<<
 
8357
 *         c_cur = c_next + 1
 
8358
 *         cur_record.record_start = strtoul(c_cur, &c_next, 10)
 
8359
 */
 
8360
  __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8361
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_44));
 
8362
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_43));
 
8363
  PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43));
 
8364
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43));
 
8365
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44));
 
8366
 
 
8367
  /* "bzrlib/_btree_serializer_pyx.pyx":765
 
8368
 *         cur_record.record_start = strtoul(c_cur, &c_next, 10)
 
8369
 *         if c_cur == c_next or c_next[0] != c' ':
 
8370
 *             raise ValueError('Failed to parse block length')             # <<<<<<<<<<<<<<
 
8371
 *         c_cur = c_next + 1
 
8372
 *         cur_record.record_end = strtoul(c_cur, &c_next, 10)
 
8373
 */
 
8374
  __pyx_k_tuple_45 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8375
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_45));
 
8376
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_43));
 
8377
  PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, ((PyObject *)__pyx_kp_s_43));
 
8378
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43));
 
8379
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45));
 
8380
 
 
8381
  /* "bzrlib/_btree_serializer_pyx.pyx":769
 
8382
 *         cur_record.record_end = strtoul(c_cur, &c_next, 10)
 
8383
 *         if c_cur == c_next or c_next[0] != c'\n':
 
8384
 *             raise ValueError('Failed to parse record end')             # <<<<<<<<<<<<<<
 
8385
 *         c_cur = c_next + 1
 
8386
 *         return c_cur
 
8387
 */
 
8388
  __pyx_k_tuple_47 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8389
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_47));
 
8390
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
 
8391
  PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_kp_s_46));
 
8392
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_46));
 
8393
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));
 
8394
  __Pyx_RefNannyFinishContext();
 
8395
  return 0;
 
8396
  __pyx_L1_error:;
 
8397
  __Pyx_RefNannyFinishContext();
 
8398
  return -1;
 
8399
}
 
8400
 
 
8401
static int __Pyx_InitGlobals(void) {
 
8402
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8403
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8404
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8405
  __pyx_int_2147483648 = PyInt_FromString((char *)"2147483648", 0, 0); if (unlikely(!__pyx_int_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8406
  __pyx_int_4294967295 = PyInt_FromString((char *)"4294967295", 0, 0); if (unlikely(!__pyx_int_4294967295)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8407
  return 0;
 
8408
  __pyx_L1_error:;
 
8409
  return -1;
 
8410
}
 
8411
 
 
8412
#if PY_MAJOR_VERSION < 3
 
8413
PyMODINIT_FUNC init_btree_serializer_pyx(void); /*proto*/
 
8414
PyMODINIT_FUNC init_btree_serializer_pyx(void)
 
8415
#else
 
8416
PyMODINIT_FUNC PyInit__btree_serializer_pyx(void); /*proto*/
 
8417
PyMODINIT_FUNC PyInit__btree_serializer_pyx(void)
 
8418
#endif
 
8419
{
 
8420
  PyObject *__pyx_t_1 = NULL;
 
8421
  int __pyx_t_2;
 
8422
  #if CYTHON_REFNANNY
 
8423
  void* __pyx_refnanny = NULL;
 
8424
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
 
8425
  if (!__Pyx_RefNanny) {
 
8426
      PyErr_Clear();
 
8427
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
 
8428
      if (!__Pyx_RefNanny)
 
8429
          Py_FatalError("failed to import 'refnanny' module");
 
8430
  }
 
8431
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__btree_serializer_pyx(void)", __LINE__, __FILE__);
 
8432
  #endif
 
8433
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8434
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8435
  #ifdef __pyx_binding_PyCFunctionType_USED
 
8436
  if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8437
  #endif
 
8438
  /*--- Library function declarations ---*/
 
8439
  /*--- Threads initialization code ---*/
 
8440
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
 
8441
  #ifdef WITH_THREAD /* Python build with threading support? */
 
8442
  PyEval_InitThreads();
 
8443
  #endif
 
8444
  #endif
 
8445
  /*--- Module creation code ---*/
 
8446
  #if PY_MAJOR_VERSION < 3
 
8447
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_btree_serializer_pyx"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_55), 0, PYTHON_API_VERSION);
 
8448
  #else
 
8449
  __pyx_m = PyModule_Create(&__pyx_moduledef);
 
8450
  #endif
 
8451
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8452
  #if PY_MAJOR_VERSION < 3
 
8453
  Py_INCREF(__pyx_m);
 
8454
  #endif
 
8455
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
 
8456
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8457
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8458
  /*--- Initialize various global constants etc. ---*/
 
8459
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8460
  if (__pyx_module_is_main_bzrlib___btree_serializer_pyx) {
 
8461
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
 
8462
  }
 
8463
  /*--- Builtin init code ---*/
 
8464
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8465
  /*--- Constants init code ---*/
 
8466
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8467
  /*--- Global init code ---*/
 
8468
  /*--- Function export code ---*/
 
8469
  /*--- Type init code ---*/
 
8470
  __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = &__pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
 
8471
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser.extract_key = (PyObject *(*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *, char *))__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_extract_key;
 
8472
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser.process_line = (int (*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *))__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_process_line;
 
8473
  if (PyType_Ready(&__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8474
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser.tp_dict, __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8475
  if (__Pyx_SetAttrString(__pyx_m, "BTreeLeafParser", (PyObject *)&__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8476
  __pyx_ptype_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = &__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
 
8477
  __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = &__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
 
8478
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._record_to_value_and_refs = (StaticTuple *(*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_value_and_refs;
 
8479
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._record_to_item = (StaticTuple *(*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_item;
 
8480
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._lookup_record = (__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *(*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__lookup_record;
 
8481
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._count_records = (int (*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *, char *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__count_records;
 
8482
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._parse_bytes = (PyObject *(*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, PyObject *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_bytes;
 
8483
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._parse_one_entry = (char *(*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *, char *, __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_one_entry;
 
8484
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._offset_for_sha1 = (int (*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *, char *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__offset_for_sha1;
 
8485
  __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._compute_common = (PyObject *(*)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__compute_common;
 
8486
  if (PyType_Ready(&__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8487
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode.tp_dict, __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8488
  if (__Pyx_SetAttrString(__pyx_m, "GCCHKSHA1LeafNode", (PyObject *)&__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8489
  __pyx_ptype_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = &__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
 
8490
  /*--- Type import code ---*/
 
8491
  __pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple = __Pyx_ImportType("bzrlib._static_tuple_c", "StaticTuple", sizeof(StaticTuple), 0); if (unlikely(!__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8492
  /*--- Function import code ---*/
 
8493
  /*--- Execution code ---*/
 
8494
 
 
8495
  /* "bzrlib/_btree_serializer_pyx.pyx":77
 
8496
 * # have to worry about exception checking.
 
8497
 * ## extern cdef class StaticTuple
 
8498
 * import sys             # <<<<<<<<<<<<<<
 
8499
 * 
 
8500
 * 
 
8501
 */
 
8502
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8503
  __Pyx_GOTREF(__pyx_t_1);
 
8504
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8505
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8506
 
 
8507
  /* "bzrlib/_btree_serializer_pyx.pyx":120
 
8508
 * 
 
8509
 * # This sets up the StaticTuple C_API functionality
 
8510
 * import_static_tuple_c()             # <<<<<<<<<<<<<<
 
8511
 * 
 
8512
 * 
 
8513
 */
 
8514
  __pyx_t_2 = import_static_tuple_c(); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8515
 
 
8516
  /* "bzrlib/_btree_serializer_pyx.pyx":325
 
8517
 * 
 
8518
 * 
 
8519
 * def _parse_leaf_lines(bytes, key_length, ref_list_length):             # <<<<<<<<<<<<<<
 
8520
 *     parser = BTreeLeafParser(bytes, key_length, ref_list_length)
 
8521
 *     return parser.parse()
 
8522
 */
 
8523
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines, NULL, __pyx_n_s_56); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8524
  __Pyx_GOTREF(__pyx_t_1);
 
8525
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___parse_leaf_lines, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8526
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8527
 
 
8528
  /* "bzrlib/_btree_serializer_pyx.pyx":347
 
8529
 * cdef int _unhexbuf[256]
 
8530
 * cdef char *_hexbuf
 
8531
 * _hexbuf = '0123456789abcdef'             # <<<<<<<<<<<<<<
 
8532
 * 
 
8533
 * cdef _populate_unhexbuf():
 
8534
 */
 
8535
  __pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf = __pyx_k__0123456789abcdef;
 
8536
 
 
8537
  /* "bzrlib/_btree_serializer_pyx.pyx":359
 
8538
 *     for i from 10 <= i < 16: # ABCDEF => 10, 11, 12, 13, 14, 15, 16
 
8539
 *         _unhexbuf[(i - 10 + c'A')] = i
 
8540
 * _populate_unhexbuf()             # <<<<<<<<<<<<<<
 
8541
 * 
 
8542
 * 
 
8543
 */
 
8544
  __pyx_t_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx__populate_unhexbuf(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8545
  __Pyx_GOTREF(__pyx_t_1);
 
8546
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8547
 
 
8548
  /* "bzrlib/_btree_serializer_pyx.pyx":386
 
8549
 * 
 
8550
 * 
 
8551
 * def _py_unhexlify(as_hex):             # <<<<<<<<<<<<<<
 
8552
 *     """For the test infrastructure, just thunks to _unhexlify_sha1"""
 
8553
 *     if len(as_hex) != 40 or not PyString_CheckExact(as_hex):
 
8554
 */
 
8555
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_21_btree_serializer_pyx_1_py_unhexlify, NULL, __pyx_n_s_56); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8556
  __Pyx_GOTREF(__pyx_t_1);
 
8557
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___py_unhexlify, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8558
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8559
 
 
8560
  /* "bzrlib/_btree_serializer_pyx.pyx":409
 
8561
 * 
 
8562
 * 
 
8563
 * def _py_hexlify(as_bin):             # <<<<<<<<<<<<<<
 
8564
 *     """For test infrastructure, thunk to _hexlify_sha1"""
 
8565
 *     if len(as_bin) != 20 or not PyString_CheckExact(as_bin):
 
8566
 */
 
8567
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_21_btree_serializer_pyx_2_py_hexlify, NULL, __pyx_n_s_56); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8568
  __Pyx_GOTREF(__pyx_t_1);
 
8569
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___py_hexlify, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8570
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8571
 
 
8572
  /* "bzrlib/_btree_serializer_pyx.pyx":446
 
8573
 * 
 
8574
 * 
 
8575
 * def _py_key_to_sha1(key):             # <<<<<<<<<<<<<<
 
8576
 *     """Map a key to a simple sha1 string.
 
8577
 * 
 
8578
 */
 
8579
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_21_btree_serializer_pyx_3_py_key_to_sha1, NULL, __pyx_n_s_56); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8580
  __Pyx_GOTREF(__pyx_t_1);
 
8581
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___py_key_to_sha1, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8582
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8583
 
 
8584
  /* "bzrlib/_btree_serializer_pyx.pyx":482
 
8585
 * 
 
8586
 * 
 
8587
 * def _py_sha1_to_key(sha1_bin):             # <<<<<<<<<<<<<<
 
8588
 *     """Test thunk to check the sha1 mapping."""
 
8589
 *     if not PyString_CheckExact(sha1_bin) or PyString_GET_SIZE(sha1_bin) != 20:
 
8590
 */
 
8591
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_21_btree_serializer_pyx_4_py_sha1_to_key, NULL, __pyx_n_s_56); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8592
  __Pyx_GOTREF(__pyx_t_1);
 
8593
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___py_sha1_to_key, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8594
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8595
 
 
8596
  /* "bzrlib/_btree_serializer_pyx.pyx":838
 
8597
 * 
 
8598
 * 
 
8599
 * def _parse_into_chk(bytes, key_length, ref_list_length):             # <<<<<<<<<<<<<<
 
8600
 *     """Parse into a format optimized for chk records."""
 
8601
 *     assert key_length == 1
 
8602
 */
 
8603
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_21_btree_serializer_pyx_5_parse_into_chk, NULL, __pyx_n_s_56); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8604
  __Pyx_GOTREF(__pyx_t_1);
 
8605
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___parse_into_chk, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8606
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8607
 
 
8608
  /* "bzrlib/_btree_serializer_pyx.pyx":845
 
8609
 * 
 
8610
 * 
 
8611
 * def _flatten_node(node, reference_lists):             # <<<<<<<<<<<<<<
 
8612
 *     """Convert a node into the serialized form.
 
8613
 * 
 
8614
 */
 
8615
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6bzrlib_21_btree_serializer_pyx_6_flatten_node, NULL, __pyx_n_s_56); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8616
  __Pyx_GOTREF(__pyx_t_1);
 
8617
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s___flatten_node, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8618
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
8619
 
 
8620
  /* "bzrlib/_btree_serializer_pyx.pyx":1
 
8621
 * # Copyright (C) 2008, 2009, 2010 Canonical Ltd             # <<<<<<<<<<<<<<
 
8622
 * #
 
8623
 * # This program is free software; you can redistribute it and/or modify
 
8624
 */
 
8625
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8626
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
 
8627
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
8628
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
 
8629
  goto __pyx_L0;
 
8630
  __pyx_L1_error:;
 
8631
  __Pyx_XDECREF(__pyx_t_1);
 
8632
  if (__pyx_m) {
 
8633
    __Pyx_AddTraceback("init bzrlib._btree_serializer_pyx");
 
8634
    Py_DECREF(__pyx_m); __pyx_m = 0;
 
8635
  } else if (!PyErr_Occurred()) {
 
8636
    PyErr_SetString(PyExc_ImportError, "init bzrlib._btree_serializer_pyx");
 
8637
  }
 
8638
  __pyx_L0:;
 
8639
  __Pyx_RefNannyFinishContext();
 
8640
  #if PY_MAJOR_VERSION < 3
 
8641
  return;
 
8642
  #else
 
8643
  return __pyx_m;
 
8644
  #endif
 
8645
}
 
8646
 
 
8647
/* Runtime support code */
 
8648
 
 
8649
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
 
8650
    PyObject *result;
 
8651
    result = PyObject_GetAttr(dict, name);
 
8652
    if (!result)
 
8653
        PyErr_SetObject(PyExc_NameError, name);
 
8654
    return result;
 
8655
}
 
8656
 
 
8657
static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
 
8658
    PyObject *tmp_type, *tmp_value, *tmp_tb;
 
8659
    PyThreadState *tstate = PyThreadState_GET();
 
8660
 
 
8661
    tmp_type = tstate->curexc_type;
 
8662
    tmp_value = tstate->curexc_value;
 
8663
    tmp_tb = tstate->curexc_traceback;
 
8664
    tstate->curexc_type = type;
 
8665
    tstate->curexc_value = value;
 
8666
    tstate->curexc_traceback = tb;
 
8667
    Py_XDECREF(tmp_type);
 
8668
    Py_XDECREF(tmp_value);
 
8669
    Py_XDECREF(tmp_tb);
 
8670
}
 
8671
 
 
8672
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
 
8673
    PyThreadState *tstate = PyThreadState_GET();
 
8674
    *type = tstate->curexc_type;
 
8675
    *value = tstate->curexc_value;
 
8676
    *tb = tstate->curexc_traceback;
 
8677
 
 
8678
    tstate->curexc_type = 0;
 
8679
    tstate->curexc_value = 0;
 
8680
    tstate->curexc_traceback = 0;
 
8681
}
 
8682
 
 
8683
 
 
8684
#if PY_MAJOR_VERSION < 3
 
8685
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
 
8686
    Py_XINCREF(type);
 
8687
    Py_XINCREF(value);
 
8688
    Py_XINCREF(tb);
 
8689
    /* First, check the traceback argument, replacing None with NULL. */
 
8690
    if (tb == Py_None) {
 
8691
        Py_DECREF(tb);
 
8692
        tb = 0;
 
8693
    }
 
8694
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
 
8695
        PyErr_SetString(PyExc_TypeError,
 
8696
            "raise: arg 3 must be a traceback or None");
 
8697
        goto raise_error;
 
8698
    }
 
8699
    /* Next, replace a missing value with None */
 
8700
    if (value == NULL) {
 
8701
        value = Py_None;
 
8702
        Py_INCREF(value);
 
8703
    }
 
8704
    #if PY_VERSION_HEX < 0x02050000
 
8705
    if (!PyClass_Check(type))
 
8706
    #else
 
8707
    if (!PyType_Check(type))
 
8708
    #endif
 
8709
    {
 
8710
        /* Raising an instance.  The value should be a dummy. */
 
8711
        if (value != Py_None) {
 
8712
            PyErr_SetString(PyExc_TypeError,
 
8713
                "instance exception may not have a separate value");
 
8714
            goto raise_error;
 
8715
        }
 
8716
        /* Normalize to raise <class>, <instance> */
 
8717
        Py_DECREF(value);
 
8718
        value = type;
 
8719
        #if PY_VERSION_HEX < 0x02050000
 
8720
            if (PyInstance_Check(type)) {
 
8721
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
 
8722
                Py_INCREF(type);
 
8723
            }
 
8724
            else {
 
8725
                type = 0;
 
8726
                PyErr_SetString(PyExc_TypeError,
 
8727
                    "raise: exception must be an old-style class or instance");
 
8728
                goto raise_error;
 
8729
            }
 
8730
        #else
 
8731
            type = (PyObject*) Py_TYPE(type);
 
8732
            Py_INCREF(type);
 
8733
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
 
8734
                PyErr_SetString(PyExc_TypeError,
 
8735
                    "raise: exception class must be a subclass of BaseException");
 
8736
                goto raise_error;
 
8737
            }
 
8738
        #endif
 
8739
    }
 
8740
 
 
8741
    __Pyx_ErrRestore(type, value, tb);
 
8742
    return;
 
8743
raise_error:
 
8744
    Py_XDECREF(value);
 
8745
    Py_XDECREF(type);
 
8746
    Py_XDECREF(tb);
 
8747
    return;
 
8748
}
 
8749
 
 
8750
#else /* Python 3+ */
 
8751
 
 
8752
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
 
8753
    if (tb == Py_None) {
 
8754
        tb = 0;
 
8755
    } else if (tb && !PyTraceBack_Check(tb)) {
 
8756
        PyErr_SetString(PyExc_TypeError,
 
8757
            "raise: arg 3 must be a traceback or None");
 
8758
        goto bad;
 
8759
    }
 
8760
    if (value == Py_None)
 
8761
        value = 0;
 
8762
 
 
8763
    if (PyExceptionInstance_Check(type)) {
 
8764
        if (value) {
 
8765
            PyErr_SetString(PyExc_TypeError,
 
8766
                "instance exception may not have a separate value");
 
8767
            goto bad;
 
8768
        }
 
8769
        value = type;
 
8770
        type = (PyObject*) Py_TYPE(value);
 
8771
    } else if (!PyExceptionClass_Check(type)) {
 
8772
        PyErr_SetString(PyExc_TypeError,
 
8773
            "raise: exception class must be a subclass of BaseException");
 
8774
        goto bad;
 
8775
    }
 
8776
 
 
8777
    PyErr_SetObject(type, value);
 
8778
 
 
8779
    if (tb) {
 
8780
        PyThreadState *tstate = PyThreadState_GET();
 
8781
        PyObject* tmp_tb = tstate->curexc_traceback;
 
8782
        if (tb != tmp_tb) {
 
8783
            Py_INCREF(tb);
 
8784
            tstate->curexc_traceback = tb;
 
8785
            Py_XDECREF(tmp_tb);
 
8786
        }
 
8787
    }
 
8788
 
 
8789
bad:
 
8790
    return;
 
8791
}
 
8792
#endif
 
8793
 
 
8794
static void __Pyx_RaiseArgtupleInvalid(
 
8795
    const char* func_name,
 
8796
    int exact,
 
8797
    Py_ssize_t num_min,
 
8798
    Py_ssize_t num_max,
 
8799
    Py_ssize_t num_found)
 
8800
{
 
8801
    Py_ssize_t num_expected;
 
8802
    const char *number, *more_or_less;
 
8803
 
 
8804
    if (num_found < num_min) {
 
8805
        num_expected = num_min;
 
8806
        more_or_less = "at least";
 
8807
    } else {
 
8808
        num_expected = num_max;
 
8809
        more_or_less = "at most";
 
8810
    }
 
8811
    if (exact) {
 
8812
        more_or_less = "exactly";
 
8813
    }
 
8814
    number = (num_expected == 1) ? "" : "s";
 
8815
    PyErr_Format(PyExc_TypeError,
 
8816
        #if PY_VERSION_HEX < 0x02050000
 
8817
            "%s() takes %s %d positional argument%s (%d given)",
 
8818
        #else
 
8819
            "%s() takes %s %zd positional argument%s (%zd given)",
 
8820
        #endif
 
8821
        func_name, more_or_less, num_expected, number, num_found);
 
8822
}
 
8823
 
 
8824
static void __Pyx_RaiseDoubleKeywordsError(
 
8825
    const char* func_name,
 
8826
    PyObject* kw_name)
 
8827
{
 
8828
    PyErr_Format(PyExc_TypeError,
 
8829
        #if PY_MAJOR_VERSION >= 3
 
8830
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
 
8831
        #else
 
8832
        "%s() got multiple values for keyword argument '%s'", func_name,
 
8833
        PyString_AS_STRING(kw_name));
 
8834
        #endif
 
8835
}
 
8836
 
 
8837
static int __Pyx_ParseOptionalKeywords(
 
8838
    PyObject *kwds,
 
8839
    PyObject **argnames[],
 
8840
    PyObject *kwds2,
 
8841
    PyObject *values[],
 
8842
    Py_ssize_t num_pos_args,
 
8843
    const char* function_name)
 
8844
{
 
8845
    PyObject *key = 0, *value = 0;
 
8846
    Py_ssize_t pos = 0;
 
8847
    PyObject*** name;
 
8848
    PyObject*** first_kw_arg = argnames + num_pos_args;
 
8849
 
 
8850
    while (PyDict_Next(kwds, &pos, &key, &value)) {
 
8851
        name = first_kw_arg;
 
8852
        while (*name && (**name != key)) name++;
 
8853
        if (*name) {
 
8854
            values[name-argnames] = value;
 
8855
        } else {
 
8856
            #if PY_MAJOR_VERSION < 3
 
8857
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
 
8858
            #else
 
8859
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
 
8860
            #endif
 
8861
                goto invalid_keyword_type;
 
8862
            } else {
 
8863
                for (name = first_kw_arg; *name; name++) {
 
8864
                    #if PY_MAJOR_VERSION >= 3
 
8865
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
 
8866
                        PyUnicode_Compare(**name, key) == 0) break;
 
8867
                    #else
 
8868
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
 
8869
                        _PyString_Eq(**name, key)) break;
 
8870
                    #endif
 
8871
                }
 
8872
                if (*name) {
 
8873
                    values[name-argnames] = value;
 
8874
                } else {
 
8875
                    /* unexpected keyword found */
 
8876
                    for (name=argnames; name != first_kw_arg; name++) {
 
8877
                        if (**name == key) goto arg_passed_twice;
 
8878
                        #if PY_MAJOR_VERSION >= 3
 
8879
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
 
8880
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
 
8881
                        #else
 
8882
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
 
8883
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
 
8884
                        #endif
 
8885
                    }
 
8886
                    if (kwds2) {
 
8887
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
 
8888
                    } else {
 
8889
                        goto invalid_keyword;
 
8890
                    }
 
8891
                }
 
8892
            }
 
8893
        }
 
8894
    }
 
8895
    return 0;
 
8896
arg_passed_twice:
 
8897
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
 
8898
    goto bad;
 
8899
invalid_keyword_type:
 
8900
    PyErr_Format(PyExc_TypeError,
 
8901
        "%s() keywords must be strings", function_name);
 
8902
    goto bad;
 
8903
invalid_keyword:
 
8904
    PyErr_Format(PyExc_TypeError,
 
8905
    #if PY_MAJOR_VERSION < 3
 
8906
        "%s() got an unexpected keyword argument '%s'",
 
8907
        function_name, PyString_AsString(key));
 
8908
    #else
 
8909
        "%s() got an unexpected keyword argument '%U'",
 
8910
        function_name, key);
 
8911
    #endif
 
8912
bad:
 
8913
    return -1;
 
8914
}
 
8915
 
 
8916
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
 
8917
    if (unlikely(!type)) {
 
8918
        PyErr_Format(PyExc_SystemError, "Missing type object");
 
8919
        return 0;
 
8920
    }
 
8921
    if (likely(PyObject_TypeCheck(obj, type)))
 
8922
        return 1;
 
8923
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
 
8924
                 Py_TYPE(obj)->tp_name, type->tp_name);
 
8925
    return 0;
 
8926
}
 
8927
 
 
8928
static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
 
8929
    long q = a / b;
 
8930
    long r = a - q*b;
 
8931
    q -= ((r != 0) & ((r ^ b) < 0));
 
8932
    return q;
 
8933
}
 
8934
 
 
8935
 
 
8936
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
 
8937
    PyObject *py_import = 0;
 
8938
    PyObject *empty_list = 0;
 
8939
    PyObject *module = 0;
 
8940
    PyObject *global_dict = 0;
 
8941
    PyObject *empty_dict = 0;
 
8942
    PyObject *list;
 
8943
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
 
8944
    if (!py_import)
 
8945
        goto bad;
 
8946
    if (from_list)
 
8947
        list = from_list;
 
8948
    else {
 
8949
        empty_list = PyList_New(0);
 
8950
        if (!empty_list)
 
8951
            goto bad;
 
8952
        list = empty_list;
 
8953
    }
 
8954
    global_dict = PyModule_GetDict(__pyx_m);
 
8955
    if (!global_dict)
 
8956
        goto bad;
 
8957
    empty_dict = PyDict_New();
 
8958
    if (!empty_dict)
 
8959
        goto bad;
 
8960
    module = PyObject_CallFunctionObjArgs(py_import,
 
8961
        name, global_dict, empty_dict, list, NULL);
 
8962
bad:
 
8963
    Py_XDECREF(empty_list);
 
8964
    Py_XDECREF(py_import);
 
8965
    Py_XDECREF(empty_dict);
 
8966
    return module;
 
8967
}
 
8968
 
 
8969
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
 
8970
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
 
8971
    const int is_unsigned = neg_one > const_zero;
 
8972
    if (sizeof(unsigned char) < sizeof(long)) {
 
8973
        long val = __Pyx_PyInt_AsLong(x);
 
8974
        if (unlikely(val != (long)(unsigned char)val)) {
 
8975
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
8976
                PyErr_SetString(PyExc_OverflowError,
 
8977
                    (is_unsigned && unlikely(val < 0)) ?
 
8978
                    "can't convert negative value to unsigned char" :
 
8979
                    "value too large to convert to unsigned char");
 
8980
            }
 
8981
            return (unsigned char)-1;
 
8982
        }
 
8983
        return (unsigned char)val;
 
8984
    }
 
8985
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
 
8986
}
 
8987
 
 
8988
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
 
8989
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
 
8990
    const int is_unsigned = neg_one > const_zero;
 
8991
    if (sizeof(unsigned short) < sizeof(long)) {
 
8992
        long val = __Pyx_PyInt_AsLong(x);
 
8993
        if (unlikely(val != (long)(unsigned short)val)) {
 
8994
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
8995
                PyErr_SetString(PyExc_OverflowError,
 
8996
                    (is_unsigned && unlikely(val < 0)) ?
 
8997
                    "can't convert negative value to unsigned short" :
 
8998
                    "value too large to convert to unsigned short");
 
8999
            }
 
9000
            return (unsigned short)-1;
 
9001
        }
 
9002
        return (unsigned short)val;
 
9003
    }
 
9004
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
 
9005
}
 
9006
 
 
9007
static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
 
9008
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
 
9009
    const int is_unsigned = neg_one > const_zero;
 
9010
    if (sizeof(unsigned int) < sizeof(long)) {
 
9011
        long val = __Pyx_PyInt_AsLong(x);
 
9012
        if (unlikely(val != (long)(unsigned int)val)) {
 
9013
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9014
                PyErr_SetString(PyExc_OverflowError,
 
9015
                    (is_unsigned && unlikely(val < 0)) ?
 
9016
                    "can't convert negative value to unsigned int" :
 
9017
                    "value too large to convert to unsigned int");
 
9018
            }
 
9019
            return (unsigned int)-1;
 
9020
        }
 
9021
        return (unsigned int)val;
 
9022
    }
 
9023
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
 
9024
}
 
9025
 
 
9026
static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
 
9027
    const char neg_one = (char)-1, const_zero = 0;
 
9028
    const int is_unsigned = neg_one > const_zero;
 
9029
    if (sizeof(char) < sizeof(long)) {
 
9030
        long val = __Pyx_PyInt_AsLong(x);
 
9031
        if (unlikely(val != (long)(char)val)) {
 
9032
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9033
                PyErr_SetString(PyExc_OverflowError,
 
9034
                    (is_unsigned && unlikely(val < 0)) ?
 
9035
                    "can't convert negative value to char" :
 
9036
                    "value too large to convert to char");
 
9037
            }
 
9038
            return (char)-1;
 
9039
        }
 
9040
        return (char)val;
 
9041
    }
 
9042
    return (char)__Pyx_PyInt_AsLong(x);
 
9043
}
 
9044
 
 
9045
static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
 
9046
    const short neg_one = (short)-1, const_zero = 0;
 
9047
    const int is_unsigned = neg_one > const_zero;
 
9048
    if (sizeof(short) < sizeof(long)) {
 
9049
        long val = __Pyx_PyInt_AsLong(x);
 
9050
        if (unlikely(val != (long)(short)val)) {
 
9051
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9052
                PyErr_SetString(PyExc_OverflowError,
 
9053
                    (is_unsigned && unlikely(val < 0)) ?
 
9054
                    "can't convert negative value to short" :
 
9055
                    "value too large to convert to short");
 
9056
            }
 
9057
            return (short)-1;
 
9058
        }
 
9059
        return (short)val;
 
9060
    }
 
9061
    return (short)__Pyx_PyInt_AsLong(x);
 
9062
}
 
9063
 
 
9064
static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
 
9065
    const int neg_one = (int)-1, const_zero = 0;
 
9066
    const int is_unsigned = neg_one > const_zero;
 
9067
    if (sizeof(int) < sizeof(long)) {
 
9068
        long val = __Pyx_PyInt_AsLong(x);
 
9069
        if (unlikely(val != (long)(int)val)) {
 
9070
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9071
                PyErr_SetString(PyExc_OverflowError,
 
9072
                    (is_unsigned && unlikely(val < 0)) ?
 
9073
                    "can't convert negative value to int" :
 
9074
                    "value too large to convert to int");
 
9075
            }
 
9076
            return (int)-1;
 
9077
        }
 
9078
        return (int)val;
 
9079
    }
 
9080
    return (int)__Pyx_PyInt_AsLong(x);
 
9081
}
 
9082
 
 
9083
static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
 
9084
    const signed char neg_one = (signed char)-1, const_zero = 0;
 
9085
    const int is_unsigned = neg_one > const_zero;
 
9086
    if (sizeof(signed char) < sizeof(long)) {
 
9087
        long val = __Pyx_PyInt_AsLong(x);
 
9088
        if (unlikely(val != (long)(signed char)val)) {
 
9089
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9090
                PyErr_SetString(PyExc_OverflowError,
 
9091
                    (is_unsigned && unlikely(val < 0)) ?
 
9092
                    "can't convert negative value to signed char" :
 
9093
                    "value too large to convert to signed char");
 
9094
            }
 
9095
            return (signed char)-1;
 
9096
        }
 
9097
        return (signed char)val;
 
9098
    }
 
9099
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
 
9100
}
 
9101
 
 
9102
static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
 
9103
    const signed short neg_one = (signed short)-1, const_zero = 0;
 
9104
    const int is_unsigned = neg_one > const_zero;
 
9105
    if (sizeof(signed short) < sizeof(long)) {
 
9106
        long val = __Pyx_PyInt_AsLong(x);
 
9107
        if (unlikely(val != (long)(signed short)val)) {
 
9108
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9109
                PyErr_SetString(PyExc_OverflowError,
 
9110
                    (is_unsigned && unlikely(val < 0)) ?
 
9111
                    "can't convert negative value to signed short" :
 
9112
                    "value too large to convert to signed short");
 
9113
            }
 
9114
            return (signed short)-1;
 
9115
        }
 
9116
        return (signed short)val;
 
9117
    }
 
9118
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
 
9119
}
 
9120
 
 
9121
static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
 
9122
    const signed int neg_one = (signed int)-1, const_zero = 0;
 
9123
    const int is_unsigned = neg_one > const_zero;
 
9124
    if (sizeof(signed int) < sizeof(long)) {
 
9125
        long val = __Pyx_PyInt_AsLong(x);
 
9126
        if (unlikely(val != (long)(signed int)val)) {
 
9127
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9128
                PyErr_SetString(PyExc_OverflowError,
 
9129
                    (is_unsigned && unlikely(val < 0)) ?
 
9130
                    "can't convert negative value to signed int" :
 
9131
                    "value too large to convert to signed int");
 
9132
            }
 
9133
            return (signed int)-1;
 
9134
        }
 
9135
        return (signed int)val;
 
9136
    }
 
9137
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
 
9138
}
 
9139
 
 
9140
static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
 
9141
    const int neg_one = (int)-1, const_zero = 0;
 
9142
    const int is_unsigned = neg_one > const_zero;
 
9143
    if (sizeof(int) < sizeof(long)) {
 
9144
        long val = __Pyx_PyInt_AsLong(x);
 
9145
        if (unlikely(val != (long)(int)val)) {
 
9146
            if (!unlikely(val == -1 && PyErr_Occurred())) {
 
9147
                PyErr_SetString(PyExc_OverflowError,
 
9148
                    (is_unsigned && unlikely(val < 0)) ?
 
9149
                    "can't convert negative value to int" :
 
9150
                    "value too large to convert to int");
 
9151
            }
 
9152
            return (int)-1;
 
9153
        }
 
9154
        return (int)val;
 
9155
    }
 
9156
    return (int)__Pyx_PyInt_AsLong(x);
 
9157
}
 
9158
 
 
9159
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
 
9160
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
 
9161
    const int is_unsigned = neg_one > const_zero;
 
9162
#if PY_VERSION_HEX < 0x03000000
 
9163
    if (likely(PyInt_Check(x))) {
 
9164
        long val = PyInt_AS_LONG(x);
 
9165
        if (is_unsigned && unlikely(val < 0)) {
 
9166
            PyErr_SetString(PyExc_OverflowError,
 
9167
                            "can't convert negative value to unsigned long");
 
9168
            return (unsigned long)-1;
 
9169
        }
 
9170
        return (unsigned long)val;
 
9171
    } else
 
9172
#endif
 
9173
    if (likely(PyLong_Check(x))) {
 
9174
        if (is_unsigned) {
 
9175
            if (unlikely(Py_SIZE(x) < 0)) {
 
9176
                PyErr_SetString(PyExc_OverflowError,
 
9177
                                "can't convert negative value to unsigned long");
 
9178
                return (unsigned long)-1;
 
9179
            }
 
9180
            return PyLong_AsUnsignedLong(x);
 
9181
        } else {
 
9182
            return PyLong_AsLong(x);
 
9183
        }
 
9184
    } else {
 
9185
        unsigned long val;
 
9186
        PyObject *tmp = __Pyx_PyNumber_Int(x);
 
9187
        if (!tmp) return (unsigned long)-1;
 
9188
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
 
9189
        Py_DECREF(tmp);
 
9190
        return val;
 
9191
    }
 
9192
}
 
9193
 
 
9194
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
 
9195
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
 
9196
    const int is_unsigned = neg_one > const_zero;
 
9197
#if PY_VERSION_HEX < 0x03000000
 
9198
    if (likely(PyInt_Check(x))) {
 
9199
        long val = PyInt_AS_LONG(x);
 
9200
        if (is_unsigned && unlikely(val < 0)) {
 
9201
            PyErr_SetString(PyExc_OverflowError,
 
9202
                            "can't convert negative value to unsigned PY_LONG_LONG");
 
9203
            return (unsigned PY_LONG_LONG)-1;
 
9204
        }
 
9205
        return (unsigned PY_LONG_LONG)val;
 
9206
    } else
 
9207
#endif
 
9208
    if (likely(PyLong_Check(x))) {
 
9209
        if (is_unsigned) {
 
9210
            if (unlikely(Py_SIZE(x) < 0)) {
 
9211
                PyErr_SetString(PyExc_OverflowError,
 
9212
                                "can't convert negative value to unsigned PY_LONG_LONG");
 
9213
                return (unsigned PY_LONG_LONG)-1;
 
9214
            }
 
9215
            return PyLong_AsUnsignedLongLong(x);
 
9216
        } else {
 
9217
            return PyLong_AsLongLong(x);
 
9218
        }
 
9219
    } else {
 
9220
        unsigned PY_LONG_LONG val;
 
9221
        PyObject *tmp = __Pyx_PyNumber_Int(x);
 
9222
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
 
9223
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
 
9224
        Py_DECREF(tmp);
 
9225
        return val;
 
9226
    }
 
9227
}
 
9228
 
 
9229
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
 
9230
    const long neg_one = (long)-1, const_zero = 0;
 
9231
    const int is_unsigned = neg_one > const_zero;
 
9232
#if PY_VERSION_HEX < 0x03000000
 
9233
    if (likely(PyInt_Check(x))) {
 
9234
        long val = PyInt_AS_LONG(x);
 
9235
        if (is_unsigned && unlikely(val < 0)) {
 
9236
            PyErr_SetString(PyExc_OverflowError,
 
9237
                            "can't convert negative value to long");
 
9238
            return (long)-1;
 
9239
        }
 
9240
        return (long)val;
 
9241
    } else
 
9242
#endif
 
9243
    if (likely(PyLong_Check(x))) {
 
9244
        if (is_unsigned) {
 
9245
            if (unlikely(Py_SIZE(x) < 0)) {
 
9246
                PyErr_SetString(PyExc_OverflowError,
 
9247
                                "can't convert negative value to long");
 
9248
                return (long)-1;
 
9249
            }
 
9250
            return PyLong_AsUnsignedLong(x);
 
9251
        } else {
 
9252
            return PyLong_AsLong(x);
 
9253
        }
 
9254
    } else {
 
9255
        long val;
 
9256
        PyObject *tmp = __Pyx_PyNumber_Int(x);
 
9257
        if (!tmp) return (long)-1;
 
9258
        val = __Pyx_PyInt_AsLong(tmp);
 
9259
        Py_DECREF(tmp);
 
9260
        return val;
 
9261
    }
 
9262
}
 
9263
 
 
9264
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
 
9265
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
 
9266
    const int is_unsigned = neg_one > const_zero;
 
9267
#if PY_VERSION_HEX < 0x03000000
 
9268
    if (likely(PyInt_Check(x))) {
 
9269
        long val = PyInt_AS_LONG(x);
 
9270
        if (is_unsigned && unlikely(val < 0)) {
 
9271
            PyErr_SetString(PyExc_OverflowError,
 
9272
                            "can't convert negative value to PY_LONG_LONG");
 
9273
            return (PY_LONG_LONG)-1;
 
9274
        }
 
9275
        return (PY_LONG_LONG)val;
 
9276
    } else
 
9277
#endif
 
9278
    if (likely(PyLong_Check(x))) {
 
9279
        if (is_unsigned) {
 
9280
            if (unlikely(Py_SIZE(x) < 0)) {
 
9281
                PyErr_SetString(PyExc_OverflowError,
 
9282
                                "can't convert negative value to PY_LONG_LONG");
 
9283
                return (PY_LONG_LONG)-1;
 
9284
            }
 
9285
            return PyLong_AsUnsignedLongLong(x);
 
9286
        } else {
 
9287
            return PyLong_AsLongLong(x);
 
9288
        }
 
9289
    } else {
 
9290
        PY_LONG_LONG val;
 
9291
        PyObject *tmp = __Pyx_PyNumber_Int(x);
 
9292
        if (!tmp) return (PY_LONG_LONG)-1;
 
9293
        val = __Pyx_PyInt_AsLongLong(tmp);
 
9294
        Py_DECREF(tmp);
 
9295
        return val;
 
9296
    }
 
9297
}
 
9298
 
 
9299
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
 
9300
    const signed long neg_one = (signed long)-1, const_zero = 0;
 
9301
    const int is_unsigned = neg_one > const_zero;
 
9302
#if PY_VERSION_HEX < 0x03000000
 
9303
    if (likely(PyInt_Check(x))) {
 
9304
        long val = PyInt_AS_LONG(x);
 
9305
        if (is_unsigned && unlikely(val < 0)) {
 
9306
            PyErr_SetString(PyExc_OverflowError,
 
9307
                            "can't convert negative value to signed long");
 
9308
            return (signed long)-1;
 
9309
        }
 
9310
        return (signed long)val;
 
9311
    } else
 
9312
#endif
 
9313
    if (likely(PyLong_Check(x))) {
 
9314
        if (is_unsigned) {
 
9315
            if (unlikely(Py_SIZE(x) < 0)) {
 
9316
                PyErr_SetString(PyExc_OverflowError,
 
9317
                                "can't convert negative value to signed long");
 
9318
                return (signed long)-1;
 
9319
            }
 
9320
            return PyLong_AsUnsignedLong(x);
 
9321
        } else {
 
9322
            return PyLong_AsLong(x);
 
9323
        }
 
9324
    } else {
 
9325
        signed long val;
 
9326
        PyObject *tmp = __Pyx_PyNumber_Int(x);
 
9327
        if (!tmp) return (signed long)-1;
 
9328
        val = __Pyx_PyInt_AsSignedLong(tmp);
 
9329
        Py_DECREF(tmp);
 
9330
        return val;
 
9331
    }
 
9332
}
 
9333
 
 
9334
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
 
9335
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
 
9336
    const int is_unsigned = neg_one > const_zero;
 
9337
#if PY_VERSION_HEX < 0x03000000
 
9338
    if (likely(PyInt_Check(x))) {
 
9339
        long val = PyInt_AS_LONG(x);
 
9340
        if (is_unsigned && unlikely(val < 0)) {
 
9341
            PyErr_SetString(PyExc_OverflowError,
 
9342
                            "can't convert negative value to signed PY_LONG_LONG");
 
9343
            return (signed PY_LONG_LONG)-1;
 
9344
        }
 
9345
        return (signed PY_LONG_LONG)val;
 
9346
    } else
 
9347
#endif
 
9348
    if (likely(PyLong_Check(x))) {
 
9349
        if (is_unsigned) {
 
9350
            if (unlikely(Py_SIZE(x) < 0)) {
 
9351
                PyErr_SetString(PyExc_OverflowError,
 
9352
                                "can't convert negative value to signed PY_LONG_LONG");
 
9353
                return (signed PY_LONG_LONG)-1;
 
9354
            }
 
9355
            return PyLong_AsUnsignedLongLong(x);
 
9356
        } else {
 
9357
            return PyLong_AsLongLong(x);
 
9358
        }
 
9359
    } else {
 
9360
        signed PY_LONG_LONG val;
 
9361
        PyObject *tmp = __Pyx_PyNumber_Int(x);
 
9362
        if (!tmp) return (signed PY_LONG_LONG)-1;
 
9363
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
 
9364
        Py_DECREF(tmp);
 
9365
        return val;
 
9366
    }
 
9367
}
 
9368
 
 
9369
static void __Pyx_WriteUnraisable(const char *name) {
 
9370
    PyObject *old_exc, *old_val, *old_tb;
 
9371
    PyObject *ctx;
 
9372
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
 
9373
    #if PY_MAJOR_VERSION < 3
 
9374
    ctx = PyString_FromString(name);
 
9375
    #else
 
9376
    ctx = PyUnicode_FromString(name);
 
9377
    #endif
 
9378
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
 
9379
    if (!ctx) {
 
9380
        PyErr_WriteUnraisable(Py_None);
 
9381
    } else {
 
9382
        PyErr_WriteUnraisable(ctx);
 
9383
        Py_DECREF(ctx);
 
9384
    }
 
9385
}
 
9386
 
 
9387
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
 
9388
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
 
9389
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
 
9390
#else
 
9391
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
 
9392
#endif
 
9393
    if (!ob)
 
9394
        goto bad;
 
9395
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
 
9396
        goto bad;
 
9397
    Py_DECREF(ob);
 
9398
    return 0;
 
9399
bad:
 
9400
    Py_XDECREF(ob);
 
9401
    return -1;
 
9402
}
 
9403
 
 
9404
#ifndef __PYX_HAVE_RT_ImportType
 
9405
#define __PYX_HAVE_RT_ImportType
 
9406
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
 
9407
    long size, int strict)
 
9408
{
 
9409
    PyObject *py_module = 0;
 
9410
    PyObject *result = 0;
 
9411
    PyObject *py_name = 0;
 
9412
    char warning[200];
 
9413
 
 
9414
    py_module = __Pyx_ImportModule(module_name);
 
9415
    if (!py_module)
 
9416
        goto bad;
 
9417
    #if PY_MAJOR_VERSION < 3
 
9418
    py_name = PyString_FromString(class_name);
 
9419
    #else
 
9420
    py_name = PyUnicode_FromString(class_name);
 
9421
    #endif
 
9422
    if (!py_name)
 
9423
        goto bad;
 
9424
    result = PyObject_GetAttr(py_module, py_name);
 
9425
    Py_DECREF(py_name);
 
9426
    py_name = 0;
 
9427
    Py_DECREF(py_module);
 
9428
    py_module = 0;
 
9429
    if (!result)
 
9430
        goto bad;
 
9431
    if (!PyType_Check(result)) {
 
9432
        PyErr_Format(PyExc_TypeError,
 
9433
            "%s.%s is not a type object",
 
9434
            module_name, class_name);
 
9435
        goto bad;
 
9436
    }
 
9437
    if (!strict && ((PyTypeObject *)result)->tp_basicsize > size) {
 
9438
        PyOS_snprintf(warning, sizeof(warning),
 
9439
            "%s.%s size changed, may indicate binary incompatibility",
 
9440
            module_name, class_name);
 
9441
        #if PY_VERSION_HEX < 0x02050000
 
9442
        PyErr_Warn(NULL, warning);
 
9443
        #else
 
9444
        PyErr_WarnEx(NULL, warning, 0);
 
9445
        #endif
 
9446
    }
 
9447
    else if (((PyTypeObject *)result)->tp_basicsize != size) {
 
9448
        PyErr_Format(PyExc_ValueError,
 
9449
            "%s.%s has the wrong size, try recompiling",
 
9450
            module_name, class_name);
 
9451
        goto bad;
 
9452
    }
 
9453
    return (PyTypeObject *)result;
 
9454
bad:
 
9455
    Py_XDECREF(py_module);
 
9456
    Py_XDECREF(result);
 
9457
    return 0;
 
9458
}
 
9459
#endif
 
9460
 
 
9461
#ifndef __PYX_HAVE_RT_ImportModule
 
9462
#define __PYX_HAVE_RT_ImportModule
 
9463
static PyObject *__Pyx_ImportModule(const char *name) {
 
9464
    PyObject *py_name = 0;
 
9465
    PyObject *py_module = 0;
 
9466
 
 
9467
    #if PY_MAJOR_VERSION < 3
 
9468
    py_name = PyString_FromString(name);
 
9469
    #else
 
9470
    py_name = PyUnicode_FromString(name);
 
9471
    #endif
 
9472
    if (!py_name)
 
9473
        goto bad;
 
9474
    py_module = PyImport_Import(py_name);
 
9475
    Py_DECREF(py_name);
 
9476
    return py_module;
 
9477
bad:
 
9478
    Py_XDECREF(py_name);
 
9479
    return 0;
 
9480
}
 
9481
#endif
 
9482
 
 
9483
#include "compile.h"
 
9484
#include "frameobject.h"
 
9485
#include "traceback.h"
 
9486
 
 
9487
static void __Pyx_AddTraceback(const char *funcname) {
 
9488
    PyObject *py_srcfile = 0;
 
9489
    PyObject *py_funcname = 0;
 
9490
    PyObject *py_globals = 0;
 
9491
    PyCodeObject *py_code = 0;
 
9492
    PyFrameObject *py_frame = 0;
 
9493
 
 
9494
    #if PY_MAJOR_VERSION < 3
 
9495
    py_srcfile = PyString_FromString(__pyx_filename);
 
9496
    #else
 
9497
    py_srcfile = PyUnicode_FromString(__pyx_filename);
 
9498
    #endif
 
9499
    if (!py_srcfile) goto bad;
 
9500
    if (__pyx_clineno) {
 
9501
        #if PY_MAJOR_VERSION < 3
 
9502
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
 
9503
        #else
 
9504
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
 
9505
        #endif
 
9506
    }
 
9507
    else {
 
9508
        #if PY_MAJOR_VERSION < 3
 
9509
        py_funcname = PyString_FromString(funcname);
 
9510
        #else
 
9511
        py_funcname = PyUnicode_FromString(funcname);
 
9512
        #endif
 
9513
    }
 
9514
    if (!py_funcname) goto bad;
 
9515
    py_globals = PyModule_GetDict(__pyx_m);
 
9516
    if (!py_globals) goto bad;
 
9517
    py_code = PyCode_New(
 
9518
        0,            /*int argcount,*/
 
9519
        #if PY_MAJOR_VERSION >= 3
 
9520
        0,            /*int kwonlyargcount,*/
 
9521
        #endif
 
9522
        0,            /*int nlocals,*/
 
9523
        0,            /*int stacksize,*/
 
9524
        0,            /*int flags,*/
 
9525
        __pyx_empty_bytes, /*PyObject *code,*/
 
9526
        __pyx_empty_tuple,  /*PyObject *consts,*/
 
9527
        __pyx_empty_tuple,  /*PyObject *names,*/
 
9528
        __pyx_empty_tuple,  /*PyObject *varnames,*/
 
9529
        __pyx_empty_tuple,  /*PyObject *freevars,*/
 
9530
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
 
9531
        py_srcfile,   /*PyObject *filename,*/
 
9532
        py_funcname,  /*PyObject *name,*/
 
9533
        __pyx_lineno,   /*int firstlineno,*/
 
9534
        __pyx_empty_bytes  /*PyObject *lnotab*/
 
9535
    );
 
9536
    if (!py_code) goto bad;
 
9537
    py_frame = PyFrame_New(
 
9538
        PyThreadState_GET(), /*PyThreadState *tstate,*/
 
9539
        py_code,             /*PyCodeObject *code,*/
 
9540
        py_globals,          /*PyObject *globals,*/
 
9541
        0                    /*PyObject *locals*/
 
9542
    );
 
9543
    if (!py_frame) goto bad;
 
9544
    py_frame->f_lineno = __pyx_lineno;
 
9545
    PyTraceBack_Here(py_frame);
 
9546
bad:
 
9547
    Py_XDECREF(py_srcfile);
 
9548
    Py_XDECREF(py_funcname);
 
9549
    Py_XDECREF(py_code);
 
9550
    Py_XDECREF(py_frame);
 
9551
}
 
9552
 
 
9553
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
 
9554
    while (t->p) {
 
9555
        #if PY_MAJOR_VERSION < 3
 
9556
        if (t->is_unicode) {
 
9557
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
 
9558
        } else if (t->intern) {
 
9559
            *t->p = PyString_InternFromString(t->s);
 
9560
        } else {
 
9561
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
 
9562
        }
 
9563
        #else  /* Python 3+ has unicode identifiers */
 
9564
        if (t->is_unicode | t->is_str) {
 
9565
            if (t->intern) {
 
9566
                *t->p = PyUnicode_InternFromString(t->s);
 
9567
            } else if (t->encoding) {
 
9568
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
 
9569
            } else {
 
9570
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
 
9571
            }
 
9572
        } else {
 
9573
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
 
9574
        }
 
9575
        #endif
 
9576
        if (!*t->p)
 
9577
            return -1;
 
9578
        ++t;
 
9579
    }
 
9580
    return 0;
 
9581
}
 
9582
 
 
9583
/* Type Conversion Functions */
 
9584
 
 
9585
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
 
9586
   int is_true = x == Py_True;
 
9587
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
 
9588
   else return PyObject_IsTrue(x);
 
9589
}
 
9590
 
 
9591
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
 
9592
  PyNumberMethods *m;
 
9593
  const char *name = NULL;
 
9594
  PyObject *res = NULL;
 
9595
#if PY_VERSION_HEX < 0x03000000
 
9596
  if (PyInt_Check(x) || PyLong_Check(x))
 
9597
#else
 
9598
  if (PyLong_Check(x))
 
9599
#endif
 
9600
    return Py_INCREF(x), x;
 
9601
  m = Py_TYPE(x)->tp_as_number;
 
9602
#if PY_VERSION_HEX < 0x03000000
 
9603
  if (m && m->nb_int) {
 
9604
    name = "int";
 
9605
    res = PyNumber_Int(x);
 
9606
  }
 
9607
  else if (m && m->nb_long) {
 
9608
    name = "long";
 
9609
    res = PyNumber_Long(x);
 
9610
  }
 
9611
#else
 
9612
  if (m && m->nb_int) {
 
9613
    name = "int";
 
9614
    res = PyNumber_Long(x);
 
9615
  }
 
9616
#endif
 
9617
  if (res) {
 
9618
#if PY_VERSION_HEX < 0x03000000
 
9619
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
 
9620
#else
 
9621
    if (!PyLong_Check(res)) {
 
9622
#endif
 
9623
      PyErr_Format(PyExc_TypeError,
 
9624
                   "__%s__ returned non-%s (type %.200s)",
 
9625
                   name, name, Py_TYPE(res)->tp_name);
 
9626
      Py_DECREF(res);
 
9627
      return NULL;
 
9628
    }
 
9629
  }
 
9630
  else if (!PyErr_Occurred()) {
 
9631
    PyErr_SetString(PyExc_TypeError,
 
9632
                    "an integer is required");
 
9633
  }
 
9634
  return res;
 
9635
}
 
9636
 
 
9637
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
 
9638
  Py_ssize_t ival;
 
9639
  PyObject* x = PyNumber_Index(b);
 
9640
  if (!x) return -1;
 
9641
  ival = PyInt_AsSsize_t(x);
 
9642
  Py_DECREF(x);
 
9643
  return ival;
 
9644
}
 
9645
 
 
9646
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
 
9647
#if PY_VERSION_HEX < 0x02050000
 
9648
   if (ival <= LONG_MAX)
 
9649
       return PyInt_FromLong((long)ival);
 
9650
   else {
 
9651
       unsigned char *bytes = (unsigned char *) &ival;
 
9652
       int one = 1; int little = (int)*(unsigned char*)&one;
 
9653
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
 
9654
   }
 
9655
#else
 
9656
   return PyInt_FromSize_t(ival);
 
9657
#endif
 
9658
}
 
9659
 
 
9660
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
 
9661
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
 
9662
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
 
9663
       return (size_t)-1;
 
9664
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
 
9665
       PyErr_SetString(PyExc_OverflowError,
 
9666
                       "value too large to convert to size_t");
 
9667
       return (size_t)-1;
 
9668
   }
 
9669
   return (size_t)val;
 
9670
}
 
9671
 
 
9672
 
 
9673
#endif /* Py_PYTHON_H */