From cd451b7c45a847bd6fb79ba9414e4d356ad5fc1c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 9 Jun 2020 17:18:59 +0300 Subject: [PATCH] Add List::init_from. GitOrigin-RevId: 17a6f374ff0b568c6e2d056053539fb2947f22d3 --- td/telegram/logevent/SecretChatEvent.h | 2 +- tdutils/td/utils/List.h | 28 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/td/telegram/logevent/SecretChatEvent.h b/td/telegram/logevent/SecretChatEvent.h index 7b365a7c5..698e4d39b 100644 --- a/td/telegram/logevent/SecretChatEvent.h +++ b/td/telegram/logevent/SecretChatEvent.h @@ -322,7 +322,7 @@ class OutboundSecretMessage : public SecretChatLogEventBaseput(this); + init_from(std::move(other)); } } ListNode &operator=(ListNode &&other) { + if (this == &other) { + return *this; + } + this->remove(); if (!other.empty()) { - ListNode *head = other.prev; - other.remove(); - head->put(this); + init_from(std::move(other)); } return *this; @@ -58,11 +58,12 @@ struct ListNode { } void put(ListNode *other) { - other->connect(next); - this->connect(other); + DCHECK(other->empty()); + put_unsafe(other); } void put_back(ListNode *other) { + DCHECK(other->empty()); prev->connect(other); other->connect(this); } @@ -87,6 +88,17 @@ struct ListNode { next = this; prev = this; } + + void init_from(ListNode &&other) { + ListNode *head = other.prev; + other.remove(); + head->put_unsafe(this); + } + + void put_unsafe(ListNode *other) { + other->connect(next); + this->connect(other); + } }; } // namespace td