Patchwork [2,of,3,V2] lazymanifest: extract function for iterating to next line

login
register
mail settings
Submitter Martin von Zweigbergk
Date March 12, 2015, 11:14 p.m.
Message ID <31534b690c4630f11076.1426202073@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/8036/
State Accepted
Commit 3d485727e45ef4ceb3edb8b123ad58f49ae8a9fd
Headers show

Comments

Martin von Zweigbergk - March 12, 2015, 11:14 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1426104926 25200
#      Wed Mar 11 13:15:26 2015 -0700
# Node ID 31534b690c4630f11076b1228eff56c2f58e5e9d
# Parent  c13f6aa77c70ecb227cca08d9221de0492ff0848
lazymanifest: extract function for iterating to next line

This will soon be reused by keys iterator.

Patch

diff -r c13f6aa77c70 -r 31534b690c46 mercurial/manifest.c
--- 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 = {