* Update lists.nim * Update tlists.nim * removed check `if b.tail != nil` The tail of the list being null it is still possible to retrieve its end by going through all nodes from the head. So checking for null from `b.tail` is unnecessary. However, setting `a.tail = b.tail` only if `a.head != nil`, so you don't break a good list with an already broken one.
This commit is contained in:
parent
23d64be860
commit
dc5c88ca79
2 changed files with 18 additions and 5 deletions
|
|
@ -530,11 +530,12 @@ proc addMoved*[T](a, b: var SinglyLinkedList[T]) {.since: (1, 5, 1).} =
|
||||||
ci
|
ci
|
||||||
assert s == [0, 1, 0, 1, 0, 1]
|
assert s == [0, 1, 0, 1, 0, 1]
|
||||||
|
|
||||||
if a.tail != nil:
|
if b.head != nil:
|
||||||
a.tail.next = b.head
|
|
||||||
a.tail = b.tail
|
|
||||||
if a.head == nil:
|
if a.head == nil:
|
||||||
a.head = b.head
|
a.head = b.head
|
||||||
|
else:
|
||||||
|
a.tail.next = b.head
|
||||||
|
a.tail = b.tail
|
||||||
if a.addr != b.addr:
|
if a.addr != b.addr:
|
||||||
b.head = nil
|
b.head = nil
|
||||||
b.tail = nil
|
b.tail = nil
|
||||||
|
|
|
||||||
|
|
@ -234,5 +234,17 @@ template main =
|
||||||
doAssert l.remove(l.head) == true
|
doAssert l.remove(l.head) == true
|
||||||
doAssert l.toSeq == []
|
doAssert l.toSeq == []
|
||||||
|
|
||||||
|
block issue19297: # add (appends a shallow copy)
|
||||||
|
var a: SinglyLinkedList[int]
|
||||||
|
var b: SinglyLinkedList[int]
|
||||||
|
|
||||||
|
doAssert a.toSeq == @[]
|
||||||
|
a.add(1)
|
||||||
|
doAssert a.toSeq == @[1]
|
||||||
|
a.add(b)
|
||||||
|
doAssert a.toSeq == @[1]
|
||||||
|
a.add(2)
|
||||||
|
doAssert a.toSeq == @[1, 2]
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue