[PATCH 4 of 6] obsolete: add native version of addsuccessors()

Martin von Zweigbergk martinvonz at google.com
Tue Feb 3 22:01:11 CST 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1421909060 28800
#      Wed Jan 21 22:44:20 2015 -0800
# Node ID c6828c4acf92b415ee722371d781b28870f17e7e
# Parent  cd65758885ab3cc6649001fa9aa68105d818323a
obsolete: add native version of addsuccessors()

This speeds up 'hg status' from 0.438s to 0.425s.

diff -r cd65758885ab -r c6828c4acf92 mercurial/obsolete.py
--- a/mercurial/obsolete.py	Tue Jan 20 22:34:57 2015 -0800
+++ b/mercurial/obsolete.py	Wed Jan 21 22:44:20 2015 -0800
@@ -607,6 +607,11 @@
 
     @util.nogc
     def _addsuccessors(self, markers):
+        native = getattr(parsers, 'addsuccessors', None)
+        if native:
+            native(markers, self._successors)
+            return
+
         for mark in markers:
             self._successors.setdefault(mark[0], set()).add(mark)
 
diff -r cd65758885ab -r c6828c4acf92 mercurial/parsers.c
--- a/mercurial/parsers.c	Tue Jan 20 22:34:57 2015 -0800
+++ b/mercurial/parsers.c	Wed Jan 21 22:44:20 2015 -0800
@@ -2294,6 +2294,46 @@
 	return NULL;
 }
 
+static PyObject *setdefaultemptyset(PyObject *dict, PyObject *key) {
+	PyObject *set = PyDict_GetItem(dict, key);
+	if (!set) {
+		set = PySet_New(NULL);
+		if (!set) {
+			return NULL;
+		}
+		PyDict_SetItem(dict, key, set);
+		Py_DECREF(set);
+	}
+	return set;
+}
+
+static PyObject *addsuccessors(PyObject *self, PyObject *args) {
+	PyObject *markers;
+	PyObject *successors;
+	PyObject *iterator;
+	PyObject *marker;
+
+	if (!PyArg_ParseTuple(args, "OO", &markers, &successors)) {
+		return NULL;
+	}
+
+	iterator = PyObject_GetIter(markers);
+	if (!iterator) {
+		return NULL;
+	}
+	while ((marker = PyIter_Next(iterator))) {
+		PyObject *precursor = PyTuple_GetItem(marker, 0);
+		PyObject *set = setdefaultemptyset(successors, precursor);
+		if (!set) {
+			return NULL;
+		}
+		PySet_Add(set, marker);
+		Py_DECREF(marker);
+	}
+	Py_DECREF(iterator);
+	return Py_None;
+}
+
 static char parsers_doc[] = "Efficient content parsing.";
 
 PyObject *encodedir(PyObject *self, PyObject *args);
@@ -2311,6 +2351,8 @@
 	{"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"},
 	{"fm1readmarkers", fm1readmarkers, METH_VARARGS,
 			"parse v1 obsolete markers\n"},
+	{"addsuccessors", addsuccessors, METH_VARARGS,
+			"updates successors from markers\n"},
 	{NULL, NULL}
 };
 


More information about the Mercurial-devel mailing list