[PATCH v3] parsers: add a C function to pack the dirstate

Adrian Buehlmann adrian at cadifra.com
Fri May 25 01:48:53 CDT 2012


On 2012-05-22 23:58, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano at fb.com>
> # Date 1337723862 25200
> # Node ID cc012f33398867f690963151f82c24fa1cbac89b
> # Parent  91f44cb2512919d7fe7f17f9c6f2030b6ff19b34
> parsers: add a C function to pack the dirstate
> 
> This is about 9 times faster than the Python dirstate packing code.
> The relatively small speedup is due to the poor locality and memory
> access patterns caused by traversing dicts and other boxed Python
> values.
> 

[..]

> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
> --- a/mercurial/parsers.c
> +++ b/mercurial/parsers.c
> @@ -214,6 +214,141 @@ quit:
>  	return ret;
>  }
>  
> +static inline int getintat(PyObject *tuple, int off, uint32_t *v)
> +{
> +	PyObject *o = PyTuple_GET_ITEM(tuple, off);
> +	if (!PyInt_Check(o)) {
> +		PyErr_SetString(PyExc_TypeError, "expected an int");
> +		return -1;
> +	}
> +	*v = (uint32_t)PyInt_AS_LONG(o);
> +	return 0;
> +}
> +

I currently have

static inline int getintat(PyObject *tuple, Py_ssize_t off, uint32_t *v)
{
	PyObject *o = PyTuple_GET_ITEM(tuple, off);
	/* on Windows, o may be a long */
	if (!PyInt_Check(o) && !PyLong_Check(o)) {
		PyErr_SetString(PyExc_TypeError, "expected an int or long");
		return -1;
	}
	*v = (uint32_t)PyInt_AsUnsignedLongMask(o);
	return 0;
}

which passes the testsuite on

  - x64 and x86 Windows (MSYS with Python 2.6.6)
  - x64 Ubuntu

But I do not (yet) understand why we get a Python long there on Windows.

Also, note that using "PyInt_AS_LONG" like this:

static inline int getintat(PyObject *tuple, Py_ssize_t off, uint32_t *v)
{
	PyObject *o = PyTuple_GET_ITEM(tuple, off);
	/* on Windows, o may be a long */
	if (!PyInt_Check(o) && !PyLong_Check(o)) {
		PyErr_SetString(PyExc_TypeError, "expected an int or long");
		return -1;
	}
	*v = (uint32_t)PyInt_AS_LONG(o);  <---
	return 0;
}

fails the testsuite on x64 Windows.



More information about the Mercurial-devel mailing list