Commit 80c8562
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 b63412e commit 80c8562
2 files changed
+20
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| |||
187 | 192 | | |
188 | 193 | | |
189 | 194 | | |
190 | | - | |
191 | | - | |
| 195 | + | |
192 | 196 | | |
| 197 | + | |
193 | 198 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 199 | + | |
| 200 | + | |
199 | 201 | | |
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
204 | | - | |
| 206 | + | |
205 | 207 | | |
206 | 208 | | |
207 | 209 | | |
| |||
219 | 221 | | |
220 | 222 | | |
221 | 223 | | |
222 | | - | |
223 | 224 | | |
224 | | - | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | | - | |
230 | | - | |
| 228 | + | |
| 229 | + | |
231 | 230 | | |
232 | | - | |
233 | | - | |
| 231 | + | |
| 232 | + | |
234 | 233 | | |
235 | 234 | | |
236 | 235 | | |
237 | 236 | | |
238 | 237 | | |
239 | | - | |
240 | 238 | | |
241 | 239 | | |
242 | 240 | | |
| |||
288 | 286 | | |
289 | 287 | | |
290 | 288 | | |
291 | | - | |
292 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
293 | 295 | | |
294 | 296 | | |
295 | 297 | | |
| |||
| 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