[PATCH 1 of 5] parsers: add a function to efficiently lowercase ASCII strings

Antoine Pitrou solipsis at pitrou.net
Sat Oct 4 05:55:49 CDT 2014


On Fri, 3 Oct 2014 20:23:23 -0700
Siddharth Agarwal <sid0 at fb.com> wrote:
> +static PyObject *asciilower(PyObject *self, PyObject *args)
> +{
> +	char *str, *newstr;
> +	int i, len;
> +	PyObject *newobj = NULL;
> +
> +	if (!PyArg_ParseTuple(args, "s#", &str, &len))
> +		goto quit;
> +
> +	newobj = PyBytes_FromStringAndSize(NULL, len);
> +	if (!newobj)
> +		goto quit;
> +
> +	newstr = PyBytes_AS_STRING(newobj);
> +
> +	Py_MEMCPY(newstr, str, len);

Why do you memcpy() first? You could read from str directly inside the
loop.

Regards

Antoine.




More information about the Mercurial-devel mailing list