1 // Copyright 2020 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/containers/linked_list.h" 6 7 #include "base/check_op.h" 8 9 namespace base { 10 11 namespace internal { 12 13 LinkNodeBase::LinkNodeBase() = default; 14 LinkNodeBase(LinkNodeBase * previous,LinkNodeBase * next)15LinkNodeBase::LinkNodeBase(LinkNodeBase* previous, LinkNodeBase* next) 16 : previous_(previous), next_(next) {} 17 LinkNodeBase(LinkNodeBase && rhs)18LinkNodeBase::LinkNodeBase(LinkNodeBase&& rhs) { 19 next_ = rhs.next_; 20 rhs.next_ = nullptr; 21 previous_ = rhs.previous_; 22 rhs.previous_ = nullptr; 23 24 // If the node belongs to a list, next_ and previous_ are both non-null. 25 // Otherwise, they are both null. 26 if (next_) { 27 next_->previous_ = this; 28 previous_->next_ = this; 29 } 30 } 31 RemoveFromList()32void LinkNodeBase::RemoveFromList() { 33 previous_->next_ = next_; 34 next_->previous_ = previous_; 35 // next() and previous() return non-null if and only this node is not in any 36 // list. 37 next_ = nullptr; 38 previous_ = nullptr; 39 } 40 InsertBeforeBase(LinkNodeBase * e)41void LinkNodeBase::InsertBeforeBase(LinkNodeBase* e) { 42 CHECK_EQ(previous_, nullptr); 43 CHECK_EQ(next_, nullptr); 44 next_ = e; 45 previous_ = e->previous_; 46 e->previous_->next_ = this; 47 e->previous_ = this; 48 } 49 InsertAfterBase(LinkNodeBase * e)50void LinkNodeBase::InsertAfterBase(LinkNodeBase* e) { 51 CHECK_EQ(previous_, nullptr); 52 CHECK_EQ(next_, nullptr); 53 next_ = e->next_; 54 previous_ = e; 55 e->next_->previous_ = this; 56 e->next_ = this; 57 } 58 59 } // namespace internal 60 61 } // namespace base 62