[PATCH 05 of 11] parsers: use Python memory allocator for indexObject->cache
Yuya Nishihara
yuya at tcha.org
Thu Mar 9 22:32:33 EST 2017
On Thu, 09 Mar 2017 13:59:13 -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1489090097 28800
> # Thu Mar 09 12:08:17 2017 -0800
> # Node ID 4a97eb780de33a2ddce8e25ce8d91353a7630b7b
> # Parent 0c7e93c77e5a0280717ab3f0d4aaf11efa38a164
> parsers: use Python memory allocator for indexObject->cache
>
> Again, Python 2 doesn't have a calloc() equivalent. So we do a manual
> memset().
>
> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
> --- a/mercurial/parsers.c
> +++ b/mercurial/parsers.c
> @@ -882,9 +882,11 @@ static PyObject *index_get(indexObject *
> return self->cache[pos];
> }
> } else {
> - self->cache = calloc(self->raw_length, sizeof(PyObject *));
> + self->cache = PyMem_Malloc(self->raw_length * sizeof(PyObject *));
> if (self->cache == NULL)
> return PyErr_NoMemory();
> +
> + memset(self->cache, 0, self->raw_length * sizeof(PyObject *));
It's said that malloc()+memset() can be slower than calloc() in some cases.
http://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc
I have no idea how much memset() costs here, though.
More information about the Mercurial-devel
mailing list