Add List::init_from.

GitOrigin-RevId: 17a6f374ff0b568c6e2d056053539fb2947f22d3
This commit is contained in:
levlam 2020-06-09 17:18:59 +03:00
parent 64094b0a23
commit cd451b7c45
2 changed files with 21 additions and 9 deletions

View File

@ -322,7 +322,7 @@ class OutboundSecretMessage : public SecretChatLogEventBase<OutboundSecretMessag
bool is_sent = false; bool is_sent = false;
// need send push notification to the receiver // need send push notification to the receiver
// should send such messages with messages_sendEncryptedsService // should send such messages with messages_sendEncryptedService
bool need_notify_user = false; bool need_notify_user = false;
bool is_rewritable = false; bool is_rewritable = false;
// should notify our parent about state of this message (using context and random_id) // should notify our parent about state of this message (using context and random_id)

View File

@ -28,19 +28,19 @@ struct ListNode {
if (other.empty()) { if (other.empty()) {
clear(); clear();
} else { } else {
ListNode *head = other.prev; init_from(std::move(other));
other.remove();
head->put(this);
} }
} }
ListNode &operator=(ListNode &&other) { ListNode &operator=(ListNode &&other) {
if (this == &other) {
return *this;
}
this->remove(); this->remove();
if (!other.empty()) { if (!other.empty()) {
ListNode *head = other.prev; init_from(std::move(other));
other.remove();
head->put(this);
} }
return *this; return *this;
@ -58,11 +58,12 @@ struct ListNode {
} }
void put(ListNode *other) { void put(ListNode *other) {
other->connect(next); DCHECK(other->empty());
this->connect(other); put_unsafe(other);
} }
void put_back(ListNode *other) { void put_back(ListNode *other) {
DCHECK(other->empty());
prev->connect(other); prev->connect(other);
other->connect(this); other->connect(this);
} }
@ -87,6 +88,17 @@ struct ListNode {
next = this; next = this;
prev = 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 } // namespace td