From 131d96bc048a2a44b55306c0881a5463ec4e424e Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 15 Nov 2023 13:54:14 +0300 Subject: [PATCH] Optimize FullRemoteFileLocation::operator<. --- td/telegram/files/FileLocation.h | 20 ++++++-------------- td/telegram/files/FileManager.hpp | 4 ++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 9ffed2931..974de4569 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -524,25 +524,17 @@ class FullRemoteFileLocation { } bool operator<(const FullRemoteFileLocation &other) const { - auto lhs_key_type = key_type(); - auto rhs_key_type = other.key_type(); - if (lhs_key_type != rhs_key_type) { - return lhs_key_type < rhs_key_type; + if (!(variant_ == other.variant_)) { + return variant_ < other.variant_; } - if (dc_id_ != other.dc_id_) { - return dc_id_ < other.dc_id_; + if (file_type_ != other.file_type_) { + return file_type_ < other.file_type_; } - return variant_ < other.variant_; + return dc_id_ < other.dc_id_; } bool operator==(const FullRemoteFileLocation &other) const { - if (key_type() != other.key_type()) { - return false; - } - if (dc_id_ != other.dc_id_) { - return false; - } - return variant_ == other.variant_; + return variant_ == other.variant_ && file_type_ == other.file_type_ && dc_id_ == other.dc_id_; } static const int32 KEY_MAGIC = 0x64374632; diff --git a/td/telegram/files/FileManager.hpp b/td/telegram/files/FileManager.hpp index 3e815ffca..f2031c862 100644 --- a/td/telegram/files/FileManager.hpp +++ b/td/telegram/files/FileManager.hpp @@ -268,9 +268,9 @@ FileId FileManager::parse_file(ParserT &parser) { }(); if (has_encryption_key || has_secure_key) { - auto key_type = has_encryption_key ? FileEncryptionKey::Type::Secret : FileEncryptionKey::Type::Secure; + auto encryption_key_type = has_encryption_key ? FileEncryptionKey::Type::Secret : FileEncryptionKey::Type::Secure; FileEncryptionKey encryption_key; - encryption_key.parse(key_type, parser); + encryption_key.parse(encryption_key_type, parser); set_encryption_key(file_id, std::move(encryption_key)); }