Improve OrderedMessages::insert.
This commit is contained in:
parent
e39757b6ec
commit
28b742e7d3
@ -35046,18 +35046,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
|
||||
Message *result_message = message.get();
|
||||
d->messages.set(message_id, std::move(message));
|
||||
|
||||
OrderedMessage *ordered_message = d->ordered_messages.insert(message_id);
|
||||
if (!is_attached) {
|
||||
if (have_next) {
|
||||
CHECK(!have_previous);
|
||||
d->ordered_messages.attach_message_to_next(message_id, source);
|
||||
} else if (have_previous) {
|
||||
d->ordered_messages.attach_message_to_previous(message_id, source);
|
||||
}
|
||||
} else {
|
||||
ordered_message->have_previous_ = have_previous;
|
||||
ordered_message->have_next_ = have_next;
|
||||
}
|
||||
d->ordered_messages.insert(message_id, is_attached, have_previous, have_next);
|
||||
|
||||
if (m->message_id.is_yet_unsent() && !m->message_id.is_scheduled() && m->top_thread_message_id.is_valid() &&
|
||||
!td_->auth_manager_->is_bot()) {
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
OrderedMessage *OrderedMessages::insert(MessageId message_id) {
|
||||
void OrderedMessages::insert(MessageId message_id, bool was_auto_attached, bool have_previous, bool have_next) {
|
||||
auto random_y = static_cast<int32>(static_cast<uint32>(message_id.get() * 2101234567u));
|
||||
unique_ptr<OrderedMessage> *v = &messages_;
|
||||
while (*v != nullptr && (*v)->random_y_ >= random_y) {
|
||||
@ -45,7 +45,18 @@ OrderedMessage *OrderedMessages::insert(MessageId message_id) {
|
||||
CHECK(*left == nullptr);
|
||||
CHECK(*right == nullptr);
|
||||
*v = std::move(message);
|
||||
return v->get();
|
||||
|
||||
if (!was_auto_attached) {
|
||||
if (have_next) {
|
||||
CHECK(!have_previous);
|
||||
attach_message_to_next(message_id, "OrderedMessages::insert");
|
||||
} else if (have_previous) {
|
||||
attach_message_to_previous(message_id, "OrderedMessages::insert");
|
||||
}
|
||||
} else {
|
||||
(*v)->have_previous_ = have_previous;
|
||||
(*v)->have_next_ = have_next;
|
||||
}
|
||||
}
|
||||
|
||||
void OrderedMessages::erase(MessageId message_id) {
|
||||
|
@ -169,7 +169,7 @@ class OrderedMessages {
|
||||
return ConstIterator(messages_.get(), message_id);
|
||||
}
|
||||
|
||||
OrderedMessage *insert(MessageId message_id);
|
||||
void insert(MessageId message_id, bool was_auto_attached, bool have_previous, bool have_next);
|
||||
|
||||
void erase(MessageId message_id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user