Improve result handlers storage.
This commit is contained in:
parent
bb9bb91c9c
commit
d1532ef1f8
@ -3266,30 +3266,19 @@ td_api::object_ptr<td_api::Object> Td::static_request(td_api::object_ptr<td_api:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Td::add_handler(uint64 id, std::shared_ptr<ResultHandler> handler) {
|
void Td::add_handler(uint64 id, std::shared_ptr<ResultHandler> handler) {
|
||||||
result_handlers_.emplace_back(id, handler);
|
result_handlers_[id] = std::move(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Td::ResultHandler> Td::extract_handler(uint64 id) {
|
std::shared_ptr<Td::ResultHandler> Td::extract_handler(uint64 id) {
|
||||||
std::shared_ptr<Td::ResultHandler> result;
|
auto it = result_handlers_.find(id);
|
||||||
for (size_t i = 0; i < result_handlers_.size(); i++) {
|
if (it == result_handlers_.end()) {
|
||||||
if (result_handlers_[i].first == id) {
|
return nullptr;
|
||||||
result = std::move(result_handlers_[i].second);
|
|
||||||
result_handlers_.erase(result_handlers_.begin() + i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
auto result = std::move(it->second);
|
||||||
|
result_handlers_.erase(it);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::invalidate_handler(ResultHandler *handler) {
|
|
||||||
for (size_t i = 0; i < result_handlers_.size(); i++) {
|
|
||||||
if (result_handlers_[i].second.get() == handler) {
|
|
||||||
result_handlers_.erase(result_handlers_.begin() + i);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Td::send(NetQueryPtr &&query) {
|
void Td::send(NetQueryPtr &&query) {
|
||||||
VLOG(net_query) << "Send " << query << " to dispatcher";
|
VLOG(net_query) << "Send " << query << " to dispatcher";
|
||||||
query->debug("Td: send to NetQueryDispatcher");
|
query->debug("Td: send to NetQueryDispatcher");
|
||||||
@ -3640,10 +3629,6 @@ void Td::dec_request_actor_refcnt() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::clear_handlers() {
|
|
||||||
result_handlers_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Td::clear_requests() {
|
void Td::clear_requests() {
|
||||||
while (!pending_alarms_.empty()) {
|
while (!pending_alarms_.empty()) {
|
||||||
auto it = pending_alarms_.begin();
|
auto it = pending_alarms_.begin();
|
||||||
@ -3687,7 +3672,7 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "Options was cleared" << timer;
|
LOG(DEBUG) << "Options was cleared" << timer;
|
||||||
|
|
||||||
G()->net_query_creator().stop_check();
|
G()->net_query_creator().stop_check();
|
||||||
clear_handlers();
|
result_handlers_.clear();
|
||||||
LOG(DEBUG) << "Handlers was cleared" << timer;
|
LOG(DEBUG) << "Handlers was cleared" << timer;
|
||||||
G()->net_query_dispatcher().stop();
|
G()->net_query_dispatcher().stop();
|
||||||
LOG(DEBUG) << "NetQueryDispatcher was stopped" << timer;
|
LOG(DEBUG) << "NetQueryDispatcher was stopped" << timer;
|
||||||
|
@ -291,7 +291,7 @@ class Td final : public Actor {
|
|||||||
enum class State : int32 { WaitParameters, Decrypt, Run, Close } state_ = State::WaitParameters;
|
enum class State : int32 { WaitParameters, Decrypt, Run, Close } state_ = State::WaitParameters;
|
||||||
bool is_database_encrypted_ = false;
|
bool is_database_encrypted_ = false;
|
||||||
|
|
||||||
vector<std::pair<uint64, std::shared_ptr<ResultHandler>>> result_handlers_;
|
std::unordered_map<uint64, std::shared_ptr<ResultHandler>> result_handlers_;
|
||||||
enum : int8 { RequestActorIdType = 1, ActorIdType = 2 };
|
enum : int8 { RequestActorIdType = 1, ActorIdType = 2 };
|
||||||
Container<ActorOwn<Actor>> request_actors_;
|
Container<ActorOwn<Actor>> request_actors_;
|
||||||
|
|
||||||
@ -338,9 +338,6 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void add_handler(uint64 id, std::shared_ptr<ResultHandler> handler);
|
void add_handler(uint64 id, std::shared_ptr<ResultHandler> handler);
|
||||||
std::shared_ptr<ResultHandler> extract_handler(uint64 id);
|
std::shared_ptr<ResultHandler> extract_handler(uint64 id);
|
||||||
void invalidate_handler(ResultHandler *handler);
|
|
||||||
void clear_handlers();
|
|
||||||
// void destroy_handler(ResultHandler *handler);
|
|
||||||
|
|
||||||
void clear_requests();
|
void clear_requests();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user