[PATCH 4 of 4] dirs: document performance reasons for bypassing Python C API

Gregory Szorc gregory.szorc at gmail.com
Sat Oct 8 11:00:48 EDT 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1475938278 -7200
#      Sat Oct 08 16:51:18 2016 +0200
# Node ID 136b1a54213542f535f155de5ce01049b3577b4a
# Parent  da39a5835ea2d1aae1a51995b6d7e593f598be4b
dirs: document performance reasons for bypassing Python C API

So someone isn't tempted to change it.

diff --git a/mercurial/dirs.c b/mercurial/dirs.c
--- a/mercurial/dirs.c
+++ b/mercurial/dirs.c
@@ -55,8 +55,16 @@ static int _addpath(PyObject *dirs, PyOb
 	Py_ssize_t pos = PyBytes_GET_SIZE(path);
 	PyObject *key = NULL;
 	int ret = -1;
 
+	/* This loop is super critical for performance. That's why we inline
+	* access to Python structs instead of going through a supported API.
+	* The implementation, therefore, is heavily dependent on CPython
+	* implementation details. We also commit violations of the Python
+	* "protocol" such as mutating immutable objects. But since we only
+	* mutate objects created in this function or in other well-defined
+	* locations, the references are known so these violations should go
+	* unnoticed. */
 	while ((pos = _finddir(cpath, pos - 1)) != -1) {
 		PyObject *val;
 
 		/* It's likely that every prefix already has an entry


More information about the Mercurial-devel mailing list