]> Cypherpunks repositories - gostls13.git/commitdiff
container/list: remove temporary variable `n`
authorJoe Kyo <xunianzu@gmail.com>
Wed, 13 Nov 2019 06:47:41 +0000 (00:47 -0600)
committerRobert Griesemer <gri@golang.org>
Fri, 21 Feb 2020 18:32:32 +0000 (18:32 +0000)
The variable `n` for saving the pointer of the next
element when insert new element into the list turns
out to be unnecessary.

Change-Id: I17b85fd8350738815c320a83945525b60c2f04c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/207037
Reviewed-by: Robert Griesemer <gri@golang.org>
src/container/list/list.go

index b8b599aabb11d297cf7f61e31ddf11ab3dadb9dd..cc9ff0988cd863f68f03688bb6521d6c1945242f 100644 (file)
@@ -90,11 +90,10 @@ func (l *List) lazyInit() {
 
 // insert inserts e after at, increments l.len, and returns e.
 func (l *List) insert(e, at *Element) *Element {
-       n := at.next
-       at.next = e
        e.prev = at
-       e.next = n
-       n.prev = e
+       e.next = at.next
+       e.prev.next = e
+       e.next.prev = e
        e.list = l
        l.len++
        return e
@@ -124,11 +123,10 @@ func (l *List) move(e, at *Element) *Element {
        e.prev.next = e.next
        e.next.prev = e.prev
 
-       n := at.next
-       at.next = e
        e.prev = at
-       e.next = n
-       n.prev = e
+       e.next = at.next
+       e.prev.next = e
+       e.next.prev = e
 
        return e
 }