Try to get rid of an allocation

This commit is contained in:
Nicolas Werner 2021-05-30 01:09:16 +02:00
parent dfe2495d9a
commit 567078d39f
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 9 additions and 11 deletions

View file

@ -770,7 +770,7 @@ EventStore::decryptEvent(const IdIndex &idx,
} }
mtx::events::collections::TimelineEvents * mtx::events::collections::TimelineEvents *
EventStore::get(std::string_view id, std::string_view related_to, bool decrypt, bool resolve_edits) EventStore::get(std::string id, std::string_view related_to, bool decrypt, bool resolve_edits)
{ {
if (this->thread() != QThread::currentThread()) if (this->thread() != QThread::currentThread())
nhlog::db()->warn("{} called from a different thread!", __func__); nhlog::db()->warn("{} called from a different thread!", __func__);
@ -778,7 +778,7 @@ EventStore::get(std::string_view id, std::string_view related_to, bool decrypt,
if (id.empty()) if (id.empty())
return nullptr; return nullptr;
IdIndex index{room_id_, std::string(id)}; IdIndex index{room_id_, std::move(id)};
if (resolve_edits) { if (resolve_edits) {
auto edits_ = edits(index.id); auto edits_ = edits(index.id);
if (!edits_.empty()) { if (!edits_.empty()) {
@ -796,14 +796,12 @@ EventStore::get(std::string_view id, std::string_view related_to, bool decrypt,
http::client()->get_event( http::client()->get_event(
room_id_, room_id_,
index.id, index.id,
[this, [this, relatedTo = std::string(related_to), id = index.id](
relatedTo = std::string(related_to.data(), related_to.size()), const mtx::events::collections::TimelineEvents &timeline,
id = index.id](const mtx::events::collections::TimelineEvents &timeline, mtx::http::RequestErr err) {
mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->error( nhlog::net()->error(
"Failed to retrieve event with id {}, which " "Failed to retrieve event with id {}, which was "
"was "
"requested to show the replyTo for event {}", "requested to show the replyTo for event {}",
relatedTo, relatedTo,
id); id);

View file

@ -70,7 +70,7 @@ public:
// optionally returns the event or nullptr and fetches it, after which it emits a // optionally returns the event or nullptr and fetches it, after which it emits a
// relatedFetched event // relatedFetched event
mtx::events::collections::TimelineEvents *get(std::string_view id, mtx::events::collections::TimelineEvents *get(std::string id,
std::string_view related_to, std::string_view related_to,
bool decrypt = true, bool decrypt = true,
bool resolve_edits = true); bool resolve_edits = true);

View file

@ -574,7 +574,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
!event_id(event).empty() && event_id(event).front() == '$'); !event_id(event).empty() && event_id(event).front() == '$');
case IsEncrypted: { case IsEncrypted: {
auto id = event_id(event); auto id = event_id(event);
auto encrypted_event = events.get(id, id, false); auto encrypted_event = events.get(id, "", false);
return encrypted_event && return encrypted_event &&
std::holds_alternative< std::holds_alternative<
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
@ -583,7 +583,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
case Trustlevel: { case Trustlevel: {
auto id = event_id(event); auto id = event_id(event);
auto encrypted_event = events.get(id, id, false); auto encrypted_event = events.get(id, "", false);
if (encrypted_event) { if (encrypted_event) {
if (auto encrypted = if (auto encrypted =
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(