summary refs log tree commit diff stats
path: root/lib/pure/collections/sharedlist.nim
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2020-11-13 15:11:00 +0800
committerGitHub <noreply@github.com>2020-11-13 08:11:00 +0100
commit492e9afa4c32be278b61498be20ae0afc3ef3188 (patch)
treeb44ff934fee8709fac8640e0012b26ce1ecf6bc0 /lib/pure/collections/sharedlist.nim
parentd0c4c738b955f2641baa55ece6b5b90d4e632d8c (diff)
downloadNim-492e9afa4c32be278b61498be20ae0afc3ef3188.tar.gz
fix #15941 (#15948)
* fix #15941

* add testcase

* update
Diffstat (limited to 'lib/pure/collections/sharedlist.nim')
-rw-r--r--lib/pure/collections/sharedlist.nim11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/pure/collections/sharedlist.nim b/lib/pure/collections/sharedlist.nim
index 790529b79..c72477675 100644
--- a/lib/pure/collections/sharedlist.nim
+++ b/lib/pure/collections/sharedlist.nim
@@ -65,11 +65,14 @@ iterator items*[A](x: var SharedList[A]): A =
 proc add*[A](x: var SharedList[A]; y: A) =
   withLock(x):
     var node: SharedListNode[A]
-    if x.tail == nil or x.tail.dataLen == ElemsPerNode:
-      node = cast[type node](allocShared0(sizeof(node[])))
-      node.next = x.tail
+    if x.tail == nil:
+      node = cast[typeof node](allocShared0(sizeof(node[])))
+      x.tail = node
+      x.head = node
+    elif x.tail.dataLen == ElemsPerNode:
+      node = cast[typeof node](allocShared0(sizeof(node[])))
+      x.tail.next = node
       x.tail = node
-      if x.head == nil: x.head = node
     else:
       node = x.tail
     node.d[node.dataLen] = y