Add fast path in fix_formatted_text.
This commit is contained in:
parent
025cb9b6a4
commit
65b381f7fd
@ -3753,6 +3753,14 @@ static void merge_new_entities(vector<MessageEntity> &entities, vector<MessageEn
|
|||||||
|
|
||||||
Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool allow_empty, bool skip_new_entities,
|
Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool allow_empty, bool skip_new_entities,
|
||||||
bool skip_bot_commands, bool for_draft) {
|
bool skip_bot_commands, bool for_draft) {
|
||||||
|
string result;
|
||||||
|
if (entities.empty()) {
|
||||||
|
// fast path
|
||||||
|
if (!clean_input_string(text)) {
|
||||||
|
return Status::Error(400, "Strings must be encoded in UTF-8");
|
||||||
|
}
|
||||||
|
result = std::move(text);
|
||||||
|
} else {
|
||||||
if (!check_utf8(text)) {
|
if (!check_utf8(text)) {
|
||||||
return Status::Error(400, "Strings must be encoded in UTF-8");
|
return Status::Error(400, "Strings must be encoded in UTF-8");
|
||||||
}
|
}
|
||||||
@ -3769,7 +3777,8 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
|
|||||||
|
|
||||||
fix_entities(entities);
|
fix_entities(entities);
|
||||||
|
|
||||||
TRY_RESULT(result, clean_input_string_with_entities(text, entities));
|
TRY_RESULT_ASSIGN(result, clean_input_string_with_entities(text, entities));
|
||||||
|
}
|
||||||
|
|
||||||
// now entities are still sorted by offset and length, but not type,
|
// now entities are still sorted by offset and length, but not type,
|
||||||
// because some characters could be deleted and after that some entities begin to share a common end
|
// because some characters could be deleted and after that some entities begin to share a common end
|
||||||
|
Loading…
Reference in New Issue
Block a user