[PATCH 02 of 11] osutil: use Python memory allocator in _listdir

Gregory Szorc gregory.szorc at gmail.com
Thu Mar 9 16:59:10 EST 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1489089407 28800
#      Thu Mar 09 11:56:47 2017 -0800
# Node ID 4482def4ff468c6d0d5ee7f6270d8976bd264774
# Parent  7a8ce919a13a9ff6e73f391fe14d228e18387f15
osutil: use Python memory allocator in _listdir

The Python memory allocator has performance advantages
for small allocations.

diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -206,7 +206,7 @@ static PyObject *_listdir(char *path, in
 	char *pattern;
 
 	/* build the path + \* pattern string */
-	pattern = malloc(plen + 3); /* path + \* + \0 */
+	pattern = PyMem_Malloc(plen + 3); /* path + \* + \0 */
 	if (!pattern) {
 		PyErr_NoMemory();
 		goto error_nomem;
@@ -269,7 +269,7 @@ error:
 error_list:
 	FindClose(fh);
 error_file:
-	free(pattern);
+	PyMem_Free(pattern);
 error_nomem:
 	return rval;
 }


More information about the Mercurial-devel mailing list