diff options
author | flywind <xzsflywind@gmail.com> | 2021-06-16 17:31:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 11:31:20 +0200 |
commit | c51680e7012bff32156623fad0996d62f7918222 (patch) | |
tree | 6f6f8e12e02272c76966d26c42ea0f8d4c09b641 /lib/pure/collections/sharedlist.nim | |
parent | c5cf21c0c4f314e4128658d35000339d67e4824b (diff) | |
download | Nim-c51680e7012bff32156623fad0996d62f7918222.tar.gz |
fixes #17696 (#18276)
Diffstat (limited to 'lib/pure/collections/sharedlist.nim')
-rw-r--r-- | lib/pure/collections/sharedlist.nim | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/pure/collections/sharedlist.nim b/lib/pure/collections/sharedlist.nim index c72477675..79f2391f6 100644 --- a/lib/pure/collections/sharedlist.nim +++ b/lib/pure/collections/sharedlist.nim @@ -35,8 +35,10 @@ template withLock(t, x: untyped) = release(t.lock) proc iterAndMutate*[A](x: var SharedList[A]; action: proc(x: A): bool) = - ## iterates over the list. If 'action' returns true, the + ## Iterates over the list. If 'action' returns true, the ## current item is removed from the list. + ## + ## .. warning:: It may not preserve the element order after some modifications. withLock(x): var n = x.head while n != nil: @@ -47,8 +49,9 @@ proc iterAndMutate*[A](x: var SharedList[A]; action: proc(x: A): bool) = if action(n.d[i]): acquire(x.lock) let t = x.tail + dec t.dataLen # TODO considering t.dataLen == 0, + # probably the module should be refactored using doubly linked lists n.d[i] = t.d[t.dataLen] - dec t.dataLen else: acquire(x.lock) inc i |