diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-08-25 16:46:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-25 16:46:53 +0200 |
commit | 1e134aed49ea74fc6846ce875eca9c4516724439 (patch) | |
tree | 9b8c7f33d6dc849bc2d72c66a700383c5fd74fcb /lib/pure | |
parent | 9c33a5f0b194f9286413cd662f2fff57009c240f (diff) | |
parent | 8e843354e12fdaf7697cfdfe9cd4efd83737db18 (diff) | |
download | Nim-1e134aed49ea74fc6846ce875eca9c4516724439.tar.gz |
Merge pull request #4367 from kierdavis/4365-tables-clear
Improvements to tables.clear()
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/collections/tableimpl.nim | 3 | ||||
-rw-r--r-- | lib/pure/collections/tables.nim | 6 |
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/pure/collections/tableimpl.nim b/lib/pure/collections/tableimpl.nim index be3507137..a3dfd43a1 100644 --- a/lib/pure/collections/tableimpl.nim +++ b/lib/pure/collections/tableimpl.nim @@ -142,7 +142,8 @@ template delImpl() {.dirty.} = template clearImpl() {.dirty.} = for i in 0 .. <t.data.len: - t.data[i].hcode = 0 + when compiles(t.data[i].hcode): # CountTable records don't contain a hcode + t.data[i].hcode = 0 t.data[i].key = default(type(t.data[i].key)) t.data[i].val = default(type(t.data[i].val)) t.counter = 0 diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 9308095aa..3f06762ae 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -118,7 +118,7 @@ template dataLen(t): untyped = len(t.data) include tableimpl -proc clear*[A, B](t: Table[A, B] | TableRef[A, B]) = +proc clear*[A, B](t: var Table[A, B] | TableRef[A, B]) = ## Resets the table so that it is empty. clearImpl() @@ -457,7 +457,7 @@ proc len*[A, B](t: OrderedTable[A, B]): int {.inline.} = ## returns the number of keys in `t`. result = t.counter -proc clear*[A, B](t: OrderedTable[A, B] | OrderedTableRef[A, B]) = +proc clear*[A, B](t: var OrderedTable[A, B] | OrderedTableRef[A, B]) = ## Resets the table so that it is empty. clearImpl() t.first = -1 @@ -786,7 +786,7 @@ proc len*[A](t: CountTable[A]): int = ## returns the number of keys in `t`. result = t.counter -proc clear*[A](t: CountTable[A] | CountTableRef[A]) = +proc clear*[A](t: var CountTable[A] | CountTableRef[A]) = ## Resets the table so that it is empty. clearImpl() t.counter = 0 |