diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-06 22:37:27 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-06 22:37:27 +0000 |
commit | 6736ef96eab222e58e6294f42be981a5afb59811 (patch) | |
tree | 2bc668fae9bf96f9a3988e0b0a16685bde8c4f0b /libgo/go/container | |
parent | 38a138411da4206c53f9a153ee9c3624fce58a52 (diff) | |
download | gcc-6736ef96eab222e58e6294f42be981a5afb59811.zip gcc-6736ef96eab222e58e6294f42be981a5afb59811.tar.gz gcc-6736ef96eab222e58e6294f42be981a5afb59811.tar.bz2 |
libgo: Merge to master revision 19184.
The next revision, 19185, renames several runtime files, and
will be handled in a separate change.
From-SVN: r211328
Diffstat (limited to 'libgo/go/container')
-rw-r--r-- | libgo/go/container/heap/heap.go | 2 | ||||
-rwxr-xr-x | libgo/go/container/list/list.go | 8 | ||||
-rwxr-xr-x | libgo/go/container/list/list_test.go | 17 |
3 files changed, 22 insertions, 5 deletions
diff --git a/libgo/go/container/heap/heap.go b/libgo/go/container/heap/heap.go index 52c8507..3fe2327 100644 --- a/libgo/go/container/heap/heap.go +++ b/libgo/go/container/heap/heap.go @@ -22,7 +22,7 @@ import "sort" // min-heap with the following invariants (established after // Init has been called or if the data is empty or sorted): // -// !h.Less(j, i) for 0 <= i < h.Len() and j = 2*i+1 or 2*i+2 and j < h.Len() +// !h.Less(j, i) for 0 <= i < h.Len() and 2*i+1 <= j <= 2*i+2 and j < h.Len() // // Note that Push and Pop in this interface are for package heap's // implementation to call. To add and remove things from the heap, diff --git a/libgo/go/container/list/list.go b/libgo/go/container/list/list.go index 1cc7e311..0256768 100755 --- a/libgo/go/container/list/list.go +++ b/libgo/go/container/list/list.go @@ -180,18 +180,18 @@ func (l *List) MoveToBack(e *Element) { } // MoveBefore moves element e to its new position before mark. -// If e is not an element of l, or e == mark, the list is not modified. +// If e or mark is not an element of l, or e == mark, the list is not modified. func (l *List) MoveBefore(e, mark *Element) { - if e.list != l || e == mark { + if e.list != l || e == mark || mark.list != l { return } l.insert(l.remove(e), mark.prev) } // MoveAfter moves element e to its new position after mark. -// If e is not an element of l, or e == mark, the list is not modified. +// If e or mark is not an element of l, or e == mark, the list is not modified. func (l *List) MoveAfter(e, mark *Element) { - if e.list != l || e == mark { + if e.list != l || e == mark || mark.list != l { return } l.insert(l.remove(e), mark) diff --git a/libgo/go/container/list/list_test.go b/libgo/go/container/list/list_test.go index df06c42..4d8bfc2 100755 --- a/libgo/go/container/list/list_test.go +++ b/libgo/go/container/list/list_test.go @@ -324,3 +324,20 @@ func TestInsertAfterUnknownMark(t *testing.T) { l.InsertAfter(1, new(Element)) checkList(t, &l, []interface{}{1, 2, 3}) } + +// Test that a list l is not modified when calling MoveAfter or MoveBefore with a mark that is not an element of l. +func TestMoveUnkownMark(t *testing.T) { + var l1 List + e1 := l1.PushBack(1) + + var l2 List + e2 := l2.PushBack(2) + + l1.MoveAfter(e1, e2) + checkList(t, &l1, []interface{}{1}) + checkList(t, &l2, []interface{}{2}) + + l1.MoveBefore(e1, e2) + checkList(t, &l1, []interface{}{1}) + checkList(t, &l2, []interface{}{2}) +} |