summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2020-07-08 15:01:47 +0200
committerGitHub <noreply@github.com>2020-07-08 15:01:47 +0200
commit3de5296337a0711b4d907728ac24fa07791d3224 (patch)
tree9f9ac91e49e9deefd995eb405f4341c6653e43e7 /tests
parent06d776a5828d429f62c3189a99161604d50f9b96 (diff)
downloadNim-3de5296337a0711b4d907728ac24fa07791d3224.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/collections/ttables.nim10
-rw-r--r--tests/manyloc/argument_parser/argument_parser.nim3
2 files changed, 11 insertions, 2 deletions
diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim
index 392b5e93e..af8364488 100644
--- a/tests/collections/ttables.nim
+++ b/tests/collections/ttables.nim
@@ -446,3 +446,13 @@ block: # https://github.com/nim-lang/Nim/issues/13496
   testDel(): (let t = newOrderedTable[int, int]())
   testDel(): (var t: CountTable[int])
   testDel(): (let t = newCountTable[int]())
+
+
+block testNonPowerOf2:
+  var a = initTable[int, int](7)
+  a[1] = 10
+  assert a[1] == 10
+
+  var b = initTable[int, int](9)
+  b[1] = 10
+  assert b[1] == 10
diff --git a/tests/manyloc/argument_parser/argument_parser.nim b/tests/manyloc/argument_parser/argument_parser.nim
index 136d3e06b..b9788a81d 100644
--- a/tests/manyloc/argument_parser/argument_parser.nim
+++ b/tests/manyloc/argument_parser/argument_parser.nim
@@ -301,8 +301,7 @@ template build_specification_lookup():
     OrderedTable[string, ptr Tparameter_specification] =
   ## Returns the table used to keep pointers to all of the specifications.
   var result {.gensym.}: OrderedTable[string, ptr Tparameter_specification]
-  result = initOrderedTable[string, ptr Tparameter_specification](
-    tables.rightSize(expected.len))
+  result = initOrderedTable[string, ptr Tparameter_specification](expected.len)
   for i in 0..expected.len-1:
     for param_to_detect in expected[i].names:
       if result.hasKey(param_to_detect):