Patchwork [2,of,3] osutil: use PyLongObject on Python 3 for listdir_slot

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 9, 2016, 11:57 a.m.
Message ID <6bdfe20ea811ac7e8730.1476014243@gps-mbp.local>
Download mbox | patch
Permalink /patch/16984/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 9, 2016, 11:57 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1476013666 -7200
#      Sun Oct 09 13:47:46 2016 +0200
# Node ID 6bdfe20ea811ac7e873072763d43f29c23edc409
# Parent  0cc68ebd34108cc609328379b46522b81f840851
osutil: use PyLongObject on Python 3 for listdir_slot

This code looks performance sensitive. So let's retain PyIntObject on
Python 2 and use PyLongObject explicitly on Python 3.

Patch

diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -62,13 +62,21 @@  struct listdir_stat {
 	struct stat st;
 };
 #endif
 
+#ifdef IS_PY3K
+#define listdir_slot(name) \
+	static PyObject *listdir_stat_##name(PyObject *self, void *x) \
+	{ \
+		return PyLong_FromLong(((struct listdir_stat *)self)->st.name); \
+	}
+#else
 #define listdir_slot(name) \
 	static PyObject *listdir_stat_##name(PyObject *self, void *x) \
 	{ \
 		return PyInt_FromLong(((struct listdir_stat *)self)->st.name); \
 	}
+#endif
 
 listdir_slot(st_dev)
 listdir_slot(st_mode)
 listdir_slot(st_nlink)