Better MessageEntity comparator.

GitOrigin-RevId: 7522f05688c5ff4beee86d4218953dfb5f4a2821
This commit is contained in:
levlam 2019-09-23 22:57:02 +03:00
parent b13bf0ae7d
commit f20ef8c0c5
2 changed files with 19 additions and 4 deletions

View File

@ -23,6 +23,11 @@
namespace td { namespace td {
int MessageEntity::get_type_priority(Type type) {
static const int types[] = {5, 5, 5, 5, 5, 9, 9, 2, 1, 1, 5, 5, 5, 5, 9, 9, 0};
return types[static_cast<int32>(type)];
}
StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &message_entity) { StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &message_entity) {
bool has_argument = false; bool has_argument = false;
string_builder << '['; string_builder << '[';

View File

@ -19,7 +19,6 @@
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include <tuple>
#include <unordered_set> #include <unordered_set>
#include <utility> #include <utility>
@ -28,8 +27,6 @@ namespace td {
class ContactsManager; class ContactsManager;
class MessageEntity { class MessageEntity {
tl_object_ptr<td_api::TextEntityType> get_text_entity_type_object() const;
public: public:
enum class Type : int32 { enum class Type : int32 {
Mention, Mention,
@ -73,7 +70,15 @@ class MessageEntity {
} }
bool operator<(const MessageEntity &other) const { bool operator<(const MessageEntity &other) const {
return std::tie(offset, length, type) < std::tie(other.offset, other.length, other.type); if (offset != other.offset) {
return offset < other.offset;
}
if (length != other.length) {
return length > other.length;
}
auto priority = get_type_priority(type);
auto other_priority = get_type_priority(other.type);
return priority < other_priority;
} }
bool operator!=(const MessageEntity &rhs) const { bool operator!=(const MessageEntity &rhs) const {
@ -85,6 +90,11 @@ class MessageEntity {
template <class ParserT> template <class ParserT>
void parse(ParserT &parser); void parse(ParserT &parser);
private:
tl_object_ptr<td_api::TextEntityType> get_text_entity_type_object() const;
static int get_type_priority(Type type);
}; };
StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &message_entity); StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &message_entity);