changeset 45178:b00fa1782efe

phases: leverage Py_BuildValue() to build PyInt and steal PyObject "N" means "O" without incref, so we can just return the created tuple.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 18 Jul 2020 18:27:39 +0900
parents 03332e5f67e9
children ba5e4b11d085
files mercurial/cext/revlog.c
diffstat 1 files changed, 1 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Sat Jul 18 18:21:26 2020 +0900
+++ b/mercurial/cext/revlog.c	Sat Jul 18 18:27:39 2020 +0900
@@ -790,12 +790,10 @@
 	/* 0: public (untracked), 1: draft, 2: secret, 32: archive,
 	   96: internal */
 	static const char trackedphases[] = {1, 2, 32, 96};
-	PyObject *ret = NULL;
 	PyObject *roots = Py_None;
 	PyObject *pyphase = NULL;
 	PyObject *pyrev = NULL;
 	PyObject *phaseroots = NULL;
-	PyObject *phasessize = NULL;
 	PyObject *phasesets[4] = {NULL, NULL, NULL, NULL};
 	Py_ssize_t len = index_length(self);
 	char *phases = NULL;
@@ -896,14 +894,8 @@
 		Py_DECREF(phasesets[i]);
 		phasesets[i] = NULL;
 	}
-	phasessize = PyInt_FromSsize_t(len);
-	if (phasessize == NULL)
-		goto release;
 
-	ret = PyTuple_Pack(2, phasessize, phaseroots);
-	Py_DECREF(phasessize);
-	Py_DECREF(phaseroots);
-	return ret;
+	return Py_BuildValue("nN", len, phaseroots);
 
 release:
 	for (i = 0; i < numphases; ++i)