Show More
@@ -173,6 +173,18 b' static PyObject *asciiupper(PyObject *se' | |||
|
173 | 173 | return _asciitransform(str_obj, uppertable, NULL); |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | static inline PyObject *_dict_new_presized(Py_ssize_t expected_size) | |
|
177 | { | |
|
178 | /* _PyDict_NewPresized expects a minused parameter, but it actually | |
|
179 | creates a dictionary that's the nearest power of two bigger than the | |
|
180 | parameter. For example, with the initial minused = 1000, the | |
|
181 | dictionary created has size 1024. Of course in a lot of cases that | |
|
182 | can be greater than the maximum load factor Python's dict object | |
|
183 | expects (= 2/3), so as soon as we cross the threshold we'll resize | |
|
184 | anyway. So create a dictionary that's at least 3/2 the size. */ | |
|
185 | return _PyDict_NewPresized(((1 + expected_size) / 2) * 3); | |
|
186 | } | |
|
187 | ||
|
176 | 188 | static PyObject *make_file_foldmap(PyObject *self, PyObject *args) |
|
177 | 189 | { |
|
178 | 190 | PyObject *dmap, *spec_obj, *normcase_fallback; |
@@ -205,15 +217,9 b' static PyObject *make_file_foldmap(PyObj' | |||
|
205 | 217 | goto quit; |
|
206 | 218 | } |
|
207 | 219 | |
|
208 | /* _PyDict_NewPresized expects a minused parameter, but it actually | |
|
209 | creates a dictionary that's the nearest power of two bigger than the | |
|
210 | parameter. For example, with the initial minused = 1000, the | |
|
211 | dictionary created has size 1024. Of course in a lot of cases that | |
|
212 | can be greater than the maximum load factor Python's dict object | |
|
213 | expects (= 2/3), so as soon as we cross the threshold we'll resize | |
|
214 | anyway. So create a dictionary that's 3/2 the size. Also add some | |
|
215 | more to deal with additions outside this function. */ | |
|
216 | file_foldmap = _PyDict_NewPresized((PyDict_Size(dmap) / 5) * 8); | |
|
220 | /* Add some more entries to deal with additions outside this | |
|
221 | function. */ | |
|
222 | file_foldmap = _dict_new_presized((PyDict_Size(dmap) / 10) * 11); | |
|
217 | 223 | if (file_foldmap == NULL) |
|
218 | 224 | goto quit; |
|
219 | 225 |
General Comments 0
You need to be logged in to leave comments.
Login now