Mercurial > hg
changeset 24294:3d485727e45e
lazymanifest: extract function for iterating to next line
This will soon be reused by keys iterator.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 11 Mar 2015 13:15:26 -0700 |
parents | 30e9ee203846 |
children | 2b7ab29627fd |
files | mercurial/manifest.c |
diffstat | 1 files changed, 19 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/manifest.c Wed Mar 11 13:35:34 2015 -0700 +++ b/mercurial/manifest.c Wed Mar 11 13:15:26 2015 -0700 @@ -222,21 +222,28 @@ PyObject_Del(self); } +static line *lmiter_nextline(lmIter *self) +{ + do { + self->pos++; + if (self->pos >= self->m->numlines) { + return NULL; + } + /* skip over deleted manifest entries */ + } while (self->m->lines[self->pos].deleted); + return self->m->lines + self->pos; +} + static PyObject *lmiter_iternext(PyObject *o) { size_t pl; line *l; Py_ssize_t consumed; - PyObject *ret = NULL, *path = NULL, *hash = NULL, *flags = NULL; - lmIter *self = (lmIter *)o; - do { - self->pos++; - if (self->pos >= self->m->numlines) { - goto bail; - } - /* skip over deleted manifest entries */ - } while (self->m->lines[self->pos].deleted); - l = self->m->lines + self->pos; + PyObject *path = NULL, *hash = NULL, *flags = NULL; + l = lmiter_nextline((lmIter *)o); + if (!l) { + goto bail; + } pl = pathlen(l); path = PyString_FromStringAndSize(l->start, pl); hash = nodeof(l); @@ -246,12 +253,12 @@ if (!path || !hash || !flags) { goto bail; } - ret = PyTuple_Pack(3, path, hash, flags); + return PyTuple_Pack(3, path, hash, flags); bail: Py_XDECREF(path); Py_XDECREF(hash); Py_XDECREF(flags); - return ret; + return NULL; } static PyTypeObject lazymanifestIterator = {