remove a condition that table size must be passed as power of 2 (#14926)
* remove a condition that table size must be passed as power of 2 * remove power-of-2 condition from sets and sharedtables * remove power-of-2 condition from deques * use 'correctSize' for both branches * prettify changelog.md and fix typos * add a changelog entry * fix double-call of 'right-size' * fix the same thing in sets.nim * introduce a new internal proc `slotsNeeded` Deprecate the public proc `rightSize`, which is not needed anymore. Now it is an identity function, allowing the old code to work correctly and without extra allocations.
This commit is contained in:
parent
06d776a582
commit
3de5296337
10 changed files with 83 additions and 120 deletions
|
|
@ -121,12 +121,12 @@ template ctAnd(a, b): bool =
|
|||
else: false
|
||||
|
||||
template initImpl(result: typed, size: int) =
|
||||
let correctSize = slotsNeeded(size)
|
||||
when ctAnd(declared(SharedTable), type(result) is SharedTable):
|
||||
init(result, size)
|
||||
init(result, correctSize)
|
||||
else:
|
||||
assert isPowerOfTwo(size)
|
||||
result.counter = 0
|
||||
newSeq(result.data, size)
|
||||
newSeq(result.data, correctSize)
|
||||
when compiles(result.first):
|
||||
result.first = -1
|
||||
result.last = -1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue