##// END OF EJS Templates
cext: move _dict_new_presized() to header...
Yuya Nishihara -
r33751:5866ba5e default
parent child Browse files
Show More
@@ -155,18 +155,6 b' static PyObject *asciiupper(PyObject *se'
155 return _asciitransform(str_obj, uppertable, NULL);
155 return _asciitransform(str_obj, uppertable, NULL);
156 }
156 }
157
157
158 static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
159 {
160 /* _PyDict_NewPresized expects a minused parameter, but it actually
161 creates a dictionary that's the nearest power of two bigger than the
162 parameter. For example, with the initial minused = 1000, the
163 dictionary created has size 1024. Of course in a lot of cases that
164 can be greater than the maximum load factor Python's dict object
165 expects (= 2/3), so as soon as we cross the threshold we'll resize
166 anyway. So create a dictionary that's at least 3/2 the size. */
167 return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
168 }
169
170 static PyObject *dict_new_presized(PyObject *self, PyObject *args)
158 static PyObject *dict_new_presized(PyObject *self, PyObject *args)
171 {
159 {
172 Py_ssize_t expected_size;
160 Py_ssize_t expected_size;
@@ -42,6 +42,18 b' typedef unsigned char bool;'
42 #include <stdbool.h>
42 #include <stdbool.h>
43 #endif
43 #endif
44
44
45 static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
46 {
47 /* _PyDict_NewPresized expects a minused parameter, but it actually
48 creates a dictionary that's the nearest power of two bigger than the
49 parameter. For example, with the initial minused = 1000, the
50 dictionary created has size 1024. Of course in a lot of cases that
51 can be greater than the maximum load factor Python's dict object
52 expects (= 2/3), so as soon as we cross the threshold we'll resize
53 anyway. So create a dictionary that's at least 3/2 the size. */
54 return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
55 }
56
45 static const int8_t hextable[256] = {
57 static const int8_t hextable[256] = {
46 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
58 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
47 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
59 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
General Comments 0
You need to be logged in to leave comments. Login now