Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hash size calculations counting cleared keys
When the hash part of the table is resized, we count the number of still active nodes and create an array to the nearest power of two. However, our handling here was broken - we counted nodes with a nil key* and not *value*. If a table had several keys added to it, and then removed, and then a new set of keys added, this would cause both the old and new keys to be counted, causing the new hash array to be much larger than needed. While the old keys are not copied across (so they're not leaked as such), if we continue to add/remove unique keys, eventually the new map will also be saturated, and then resized to be even bigger again! This means that the length of the hash part can grow exponentially, even if the number of keys stays constant. Embarassing that this has gone un-noticed for 6 years! Fixes cc-tweaked/CC-Tweaked#1665
- Loading branch information