Mercurial > hg
comparison mercurial/parsers.c @ 24736:f2fd087a75ef
parsers: when available, use a presized dictionary for the file foldmap
On a repo with over 300,000 files, this speeds up perffilefoldmap:
before: wall 0.178421 comb 0.180000 user 0.160000 sys 0.020000 (best of 55)
after: wall 0.164462 comb 0.160000 user 0.140000 sys 0.020000 (best of 59)
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 15 Apr 2015 14:35:44 -0700 |
parents | 2262d7bc469e |
children | b3142ea2a0d4 |
comparison
equal
deleted
inserted
replaced
24735:07200e3332a1 | 24736:f2fd087a75ef |
---|---|
203 default: | 203 default: |
204 PyErr_SetString(PyExc_TypeError, "invalid normcasespec"); | 204 PyErr_SetString(PyExc_TypeError, "invalid normcasespec"); |
205 goto quit; | 205 goto quit; |
206 } | 206 } |
207 | 207 |
208 #if PY_VERSION_HEX >= 0x02060000 | |
209 /* _PyDict_NewPresized expects a minused parameter, but it actually | |
210 creates a dictionary that's the nearest power of two bigger than the | |
211 parameter. For example, with the initial minused = 1000, the | |
212 dictionary created has size 1024. Of course in a lot of cases that | |
213 can be greater than the maximum load factor Python's dict object | |
214 expects (= 2/3), so as soon as we cross the threshold we'll resize | |
215 anyway. So create a dictionary that's 3/2 the size. Also add some | |
216 more to deal with additions outside this function. */ | |
217 file_foldmap = _PyDict_NewPresized((PyDict_Size(dmap) / 5) * 8); | |
218 #else | |
208 file_foldmap = PyDict_New(); | 219 file_foldmap = PyDict_New(); |
220 #endif | |
221 | |
209 if (file_foldmap == NULL) | 222 if (file_foldmap == NULL) |
210 goto quit; | 223 goto quit; |
211 | 224 |
212 while (PyDict_Next(dmap, &pos, &k, &v)) { | 225 while (PyDict_Next(dmap, &pos, &k, &v)) { |
213 if (!dirstate_tuple_check(v)) { | 226 if (!dirstate_tuple_check(v)) { |