Commit c357227
committed
Improve Hashtable buffer grow and shrink conditions
* Move assertions about hash table sizes to Hashtable_isConsistent() so
they can be checked in all Hashtable methods.
* Slightly improve conditionals of growing and shrinking the "buckets"
buffer. Specifically the calculations are now less prone to
arithmetic overflow and can work with Hashtable.size value up to
(SIZE_MAX / 7). (Original limit was (SIZE_MAX / 10)).
* If `Hashtable.size > SIZE_MAX / sizeof(HashtableItem)`, allow the
compiler to optimize out one conditional of checking overflow.
(The buffer allocation would still fail at xCalloc() in that case.)
* Hashtable_setSize() is now a private method.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>1 parent 3ef8386 commit c357227
2 files changed
Lines changed: 20 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
76 | 81 | | |
77 | 82 | | |
78 | 83 | | |
| |||
208 | 213 | | |
209 | 214 | | |
210 | 215 | | |
211 | | - | |
212 | | - | |
| 216 | + | |
213 | 217 | | |
| 218 | + | |
214 | 219 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 220 | + | |
| 221 | + | |
220 | 222 | | |
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
224 | 226 | | |
225 | | - | |
| 227 | + | |
226 | 228 | | |
227 | 229 | | |
228 | 230 | | |
| |||
240 | 242 | | |
241 | 243 | | |
242 | 244 | | |
243 | | - | |
244 | 245 | | |
245 | | - | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
250 | | - | |
251 | | - | |
| 249 | + | |
| 250 | + | |
252 | 251 | | |
253 | | - | |
254 | | - | |
| 252 | + | |
| 253 | + | |
255 | 254 | | |
256 | 255 | | |
257 | 256 | | |
258 | 257 | | |
259 | 258 | | |
260 | | - | |
261 | 259 | | |
262 | 260 | | |
263 | 261 | | |
| |||
309 | 307 | | |
310 | 308 | | |
311 | 309 | | |
312 | | - | |
313 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
314 | 316 | | |
315 | 317 | | |
316 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | 32 | | |
35 | 33 | | |
36 | 34 | | |
| |||
0 commit comments