Patchwork [1,of,6] cext: move _dict_new_presized() to header

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 8, 2017, 2:30 p.m.
Message ID <9079b0e5c83687ce5c91.1502202620@mimosa>
Download mbox | patch
Permalink /patch/22747/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 8, 2017, 2:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1501506744 -32400
#      Mon Jul 31 22:12:24 2017 +0900
# Node ID 9079b0e5c83687ce5c918fc1364a190033408ea5
# Parent  970967e0a917d73ae76870c1533b8a32bdbf7285
cext: move _dict_new_presized() to header

Prepares for splitting encoding functions from parsers.c.

Patch

diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -155,18 +155,6 @@  static PyObject *asciiupper(PyObject *se
 	return _asciitransform(str_obj, uppertable, NULL);
 }
 
-static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
-{
-	/* _PyDict_NewPresized expects a minused parameter, but it actually
-	   creates a dictionary that's the nearest power of two bigger than the
-	   parameter. For example, with the initial minused = 1000, the
-	   dictionary created has size 1024. Of course in a lot of cases that
-	   can be greater than the maximum load factor Python's dict object
-	   expects (= 2/3), so as soon as we cross the threshold we'll resize
-	   anyway. So create a dictionary that's at least 3/2 the size. */
-	return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
-}
-
 static PyObject *dict_new_presized(PyObject *self, PyObject *args)
 {
 	Py_ssize_t expected_size;
diff --git a/mercurial/cext/util.h b/mercurial/cext/util.h
--- a/mercurial/cext/util.h
+++ b/mercurial/cext/util.h
@@ -42,6 +42,18 @@  typedef unsigned char bool;
 #include <stdbool.h>
 #endif
 
+static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
+{
+	/* _PyDict_NewPresized expects a minused parameter, but it actually
+	   creates a dictionary that's the nearest power of two bigger than the
+	   parameter. For example, with the initial minused = 1000, the
+	   dictionary created has size 1024. Of course in a lot of cases that
+	   can be greater than the maximum load factor Python's dict object
+	   expects (= 2/3), so as soon as we cross the threshold we'll resize
+	   anyway. So create a dictionary that's at least 3/2 the size. */
+	return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
+}
+
 static const int8_t hextable[256] = {
 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,