From a6ab35e6167e32aead8335aa952e81a02fa8157a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 12 Feb 2018 13:37:54 +0300 Subject: [PATCH] Replace std::max/min with td::max/min. GitOrigin-RevId: 56fb21194e995cbb37b3ebb5caed689c10320b8d --- td/mtproto/AuthData.cpp | 3 +- td/mtproto/SessionConnection.cpp | 4 +-- td/mtproto/SessionConnection.h | 3 +- td/telegram/AnimationsManager.cpp | 2 +- td/telegram/AudiosManager.cpp | 4 +-- td/telegram/AuthManager.cpp | 8 ++---- td/telegram/ClientJson.cpp | 2 -- td/telegram/ConfigManager.cpp | 3 +- td/telegram/ContactsManager.cpp | 2 +- td/telegram/Global.cpp | 6 ++-- td/telegram/Log.cpp | 4 +-- td/telegram/MessagesManager.cpp | 32 ++++++++++------------ td/telegram/StickersManager.cpp | 2 +- td/telegram/Td.cpp | 7 ++--- td/telegram/TopDialogManager.cpp | 6 ++-- td/telegram/VideoNotesManager.cpp | 4 +-- td/telegram/VideosManager.cpp | 4 +-- td/telegram/VoiceNotesManager.cpp | 4 +-- td/telegram/WebPagesManager.cpp | 7 ++--- td/telegram/files/FileDownloader.cpp | 3 +- td/telegram/files/FileLoader.cpp | 3 +- td/telegram/files/FileManager.cpp | 11 ++++---- td/telegram/files/PartsManager.cpp | 17 ++++++------ td/telegram/files/ResourceManager.cpp | 2 +- td/telegram/files/ResourceState.h | 4 +-- td/telegram/net/ConnectionCreator.cpp | 6 ++-- td/telegram/net/ConnectionCreator.h | 3 +- td/telegram/net/NetQueryDispatcher.cpp | 4 +-- td/telegram/net/TempAuthKeyWatchdog.h | 3 +- tddb/td/db/binlog/Binlog.cpp | 4 +-- tdnet/td/net/HttpChunkedByteFlow.cpp | 9 +++--- tdnet/td/net/HttpContentLengthByteFlow.cpp | 5 +--- tdutils/td/utils/BufferedReader.h | 3 +- tdutils/td/utils/FloodControlFast.h | 4 +-- tdutils/td/utils/FloodControlStrict.h | 7 ++--- tdutils/td/utils/Heap.h | 4 +-- tdutils/td/utils/Random.cpp | 3 +- tdutils/td/utils/Slice.h | 5 ++-- tdutils/td/utils/base64.cpp | 8 +++--- tdutils/td/utils/buffer.cpp | 2 +- tdutils/td/utils/buffer.h | 7 ++--- tdutils/td/utils/common.h | 12 ++++++++ tdutils/td/utils/crypto.cpp | 2 +- tdutils/td/utils/misc.h | 2 +- tdutils/td/utils/port/Fd.cpp | 3 +- 45 files changed, 101 insertions(+), 142 deletions(-) diff --git a/td/mtproto/AuthData.cpp b/td/mtproto/AuthData.cpp index 6fff40535..aa769d1d0 100644 --- a/td/mtproto/AuthData.cpp +++ b/td/mtproto/AuthData.cpp @@ -125,8 +125,7 @@ Status AuthData::check_packet(int64 session_id, int64 message_id, double now, bo // Client is to check that the session_id field in the decrypted message indeed equals to that of an active session // created by the client. if (get_session_id() != static_cast(session_id)) { - return Status::Error(PSLICE() << "Got packet from different session " - << tag("current session_id", get_session_id()) + return Status::Error(PSLICE() << "Got packet from different session " << tag("current session_id", get_session_id()) << tag("got session_id", session_id)); } diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index b11ce3aef..d21bcb1dc 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -796,8 +796,8 @@ void SessionConnection::flush_packet() { if (mode_ == Mode::HttpLongPoll) { max_delay = HTTP_MAX_DELAY; max_after = HTTP_MAX_AFTER; - max_wait = std::min(http_max_wait(), static_cast(1000 * std::max(0.1, ping_disconnect_delay() + last_pong_at_ - - Time::now_cached() - 1))); + max_wait = min(http_max_wait(), + static_cast(1000 * max(0.1, ping_disconnect_delay() + last_pong_at_ - Time::now_cached() - 1))); } else if (mode_ == Mode::Http) { max_delay = HTTP_MAX_DELAY; max_after = HTTP_MAX_AFTER; diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index eacbea66e..be3c1de89 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -21,7 +21,6 @@ #include "td/utils/StringBuilder.h" #include "td/utils/tl_parsers.h" -#include #include #include @@ -127,7 +126,7 @@ class SessionConnection bool online_flag_ = false; int rtt() const { - return std::max(2, static_cast(raw_connection_->rtt_ * 1.5)); + return max(2, static_cast(raw_connection_->rtt_ * 1.5)); } int32 ping_disconnect_delay() const { diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 5a32a99f7..6275d4df2 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -249,7 +249,7 @@ void AnimationsManager::create_animation(FileId file_id, PhotoSize thumbnail, st a->file_id = file_id; a->file_name = std::move(file_name); a->mime_type = std::move(mime_type); - a->duration = std::max(duration, 0); + a->duration = max(duration, 0); a->dimensions = dimensions; a->thumbnail = std::move(thumbnail); on_get_animation(std::move(a), replace); diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index 9fa5df4d9..8b9e1223f 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -21,8 +21,6 @@ #include "td/utils/misc.h" #include "td/utils/Status.h" -#include - namespace td { AudiosManager::AudiosManager(Td *td) : td_(td) { @@ -176,7 +174,7 @@ void AudiosManager::create_audio(FileId file_id, PhotoSize thumbnail, string fil a->file_id = file_id; a->file_name = std::move(file_name); a->mime_type = std::move(mime_type); - a->duration = std::max(duration, 0); + a->duration = max(duration, 0); a->title = std::move(title); a->performer = std::move(performer); a->thumbnail = std::move(thumbnail); diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 7c2499a77..3c0592f94 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -24,8 +24,6 @@ #include "td/utils/ScopeGuard.h" #include "td/utils/Time.h" -#include - namespace td { // SendCodeHelper @@ -43,9 +41,9 @@ td_api::object_ptr SendCodeHelper::get_autho } td_api::object_ptr SendCodeHelper::get_authentication_code_info_object() const { - return make_tl_object( - get_authentication_code_type_object(sent_code_info_), get_authentication_code_type_object(next_code_info_), - std::max(next_code_timeout_ - static_cast(Time::now()), 0)); + return make_tl_object(get_authentication_code_type_object(sent_code_info_), + get_authentication_code_type_object(next_code_info_), + max(next_code_timeout_ - static_cast(Time::now()), 0)); } Result SendCodeHelper::resend_code() { diff --git a/td/telegram/ClientJson.cpp b/td/telegram/ClientJson.cpp index c7f5d3506..f5adc09ec 100644 --- a/td/telegram/ClientJson.cpp +++ b/td/telegram/ClientJson.cpp @@ -16,8 +16,6 @@ #include "td/utils/logging.h" #include "td/utils/Status.h" -#include - namespace td { Result ClientJson::to_request(Slice request) { diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 504056634..cd5b57e90 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -38,7 +38,6 @@ #include "td/utils/Time.h" #include "td/utils/tl_parsers.h" -#include #include #include @@ -646,7 +645,7 @@ void ConfigManager::process_config(tl_object_ptr config) { bool is_from_main_dc = G()->net_query_dispatcher().main_dc_id().get_value() == config->this_dc_; LOG(INFO) << to_string(config); - auto reload_in = std::max(60 /* at least 60 seconds*/, config->expires_ - config->date_); + auto reload_in = max(60 /* at least 60 seconds*/, config->expires_ - config->date_); save_config_expire(Timestamp::in(reload_in)); reload_in -= Random::fast(0, reload_in / 5); if (!is_from_main_dc) { diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index d011665b6..fd2f7fe59 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -2267,7 +2267,7 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent if (G()->parameters().use_chat_info_db) { auto next_contacts_sync_date_string = G()->td_db()->get_binlog_pmc()->get("next_contacts_sync_date"); if (!next_contacts_sync_date_string.empty()) { - next_contacts_sync_date_ = std::min(to_integer(next_contacts_sync_date_string), G()->unix_time() + 100000); + next_contacts_sync_date_ = min(to_integer(next_contacts_sync_date_string), G()->unix_time() + 100000); } auto saved_contact_count_string = G()->td_db()->get_binlog_pmc()->get("saved_contact_count"); diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index 58ea09d77..22a3e2532 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -21,8 +21,6 @@ #include "td/utils/port/Clocks.h" #include "td/utils/tl_helpers.h" -#include - namespace td { Global::Global() = default; @@ -64,8 +62,8 @@ void Global::set_mtproto_header(std::unique_ptr mtproto_header) { Status Global::init(const TdParameters ¶meters, ActorId td, std::unique_ptr td_db) { parameters_ = parameters; - gc_scheduler_id_ = std::min(Scheduler::instance()->sched_id() + 2, Scheduler::instance()->sched_count() - 1); - slow_net_scheduler_id_ = std::min(Scheduler::instance()->sched_id() + 3, Scheduler::instance()->sched_count() - 1); + gc_scheduler_id_ = min(Scheduler::instance()->sched_id() + 2, Scheduler::instance()->sched_count() - 1); + slow_net_scheduler_id_ = min(Scheduler::instance()->sched_id() + 3, Scheduler::instance()->sched_count() - 1); td_ = td; td_db_ = std::move(td_db); diff --git a/td/telegram/Log.cpp b/td/telegram/Log.cpp index 2c1b6dde6..5aff20a87 100644 --- a/td/telegram/Log.cpp +++ b/td/telegram/Log.cpp @@ -11,8 +11,6 @@ #include "td/utils/logging.h" #include "td/utils/Slice.h" -#include - namespace td { static FileLog file_log; @@ -40,7 +38,7 @@ bool Log::set_file_path(string file_path) { } void Log::set_max_file_size(int64 max_file_size) { - max_log_file_size = std::max(max_file_size, static_cast(0)); + max_log_file_size = max(max_file_size, static_cast(0)); file_log.set_rotate_threshold(max_log_file_size); } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 953d927ff..3cba71f60 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -526,7 +526,7 @@ class GetDialogListQuery : public NetActorOnce { auto dialogs = move_tl_object_as(ptr); td->contacts_manager_->on_get_chats(std::move(dialogs->chats_)); td->contacts_manager_->on_get_users(std::move(dialogs->users_)); - td->messages_manager_->on_get_dialogs(std::move(dialogs->dialogs_), std::max(dialogs->count_, 0), + td->messages_manager_->on_get_dialogs(std::move(dialogs->dialogs_), max(dialogs->count_, 0), std::move(dialogs->messages_), std::move(promise)); } } @@ -3967,7 +3967,7 @@ void MessagesManager::Message::store(StorerT &storer) const { if (ttl_expires_at == 0) { store(-1.0, storer); } else { - double ttl_left = std::max(ttl_expires_at - Time::now_cached(), 0.0); + double ttl_left = max(ttl_expires_at - Time::now_cached(), 0.0); store(ttl_left, storer); store(server_time, storer); } @@ -4079,8 +4079,8 @@ void MessagesManager::Message::parse(ParserT &parser) { } else { double old_server_time; parse(old_server_time, parser); - double passed_server_time = std::max(parser.context()->server_time() - old_server_time, 0.0); - ttl_left = std::max(ttl_left - passed_server_time, 0.0); + double passed_server_time = max(parser.context()->server_time() - old_server_time, 0.0); + ttl_left = max(ttl_left - passed_server_time, 0.0); ttl_expires_at = Time::now_cached() + ttl_left; } } @@ -4514,7 +4514,7 @@ void MessagesManager::on_pending_message_views_timeout_callback(void *messages_m const size_t MAX_MESSAGE_VIEWS = 100; // server side limit vector message_ids; - message_ids.reserve(std::min(d->pending_viewed_message_ids.size(), MAX_MESSAGE_VIEWS)); + message_ids.reserve(min(d->pending_viewed_message_ids.size(), MAX_MESSAGE_VIEWS)); for (auto message_id : d->pending_viewed_message_ids) { message_ids.push_back(message_id); if (message_ids.size() >= MAX_MESSAGE_VIEWS) { @@ -9360,7 +9360,7 @@ std::pair> MessagesManager::creat LOG(ERROR) << "Wrong ttl = " << ttl << " received in " << message_id << " in " << dialog_id; ttl = 0; } else if (ttl > 0) { - ttl = std::max(ttl, get_message_content_duration(message_info.content.get()) + 1); + ttl = max(ttl, get_message_content_duration(message_info.content.get()) + 1); } int32 views = message_info.views; @@ -10613,14 +10613,14 @@ void MessagesManager::on_get_dialogs_from_database(vector &&dialogs // if there is no more dialogs in the database last_loaded_database_dialog_date_ = MAX_DIALOG_DATE; LOG(INFO) << "Set last loaded database dialog date to " << last_loaded_database_dialog_date_; - last_server_dialog_date_ = std::max(last_server_dialog_date_, last_database_server_dialog_date_); + last_server_dialog_date_ = max(last_server_dialog_date_, last_database_server_dialog_date_); LOG(INFO) << "Set last server dialog date to " << last_server_dialog_date_; update_last_dialog_date(); } if (last_loaded_database_dialog_date_ < max_dialog_date) { - last_loaded_database_dialog_date_ = std::min(max_dialog_date, last_database_server_dialog_date_); + last_loaded_database_dialog_date_ = min(max_dialog_date, last_database_server_dialog_date_); LOG(INFO) << "Set last loaded database dialog date to " << last_loaded_database_dialog_date_; - last_server_dialog_date_ = std::max(last_server_dialog_date_, last_loaded_database_dialog_date_); + last_server_dialog_date_ = max(last_server_dialog_date_, last_loaded_database_dialog_date_); LOG(INFO) << "Set last server dialog date to " << last_server_dialog_date_; update_last_dialog_date(); } else if (!dialogs.empty()) { @@ -10738,7 +10738,7 @@ std::pair> MessagesManager::search_dialogs(const string } promise.set_value(Unit()); - size_t result_size = std::min(static_cast(limit), recently_found_dialog_ids_.size()); + size_t result_size = min(static_cast(limit), recently_found_dialog_ids_.size()); return {recently_found_dialog_ids_.size(), vector(recently_found_dialog_ids_.begin(), recently_found_dialog_ids_.begin() + result_size)}; } @@ -12165,7 +12165,7 @@ tl_object_ptr MessagesManager::get_notificati tl_object_ptr MessagesManager::get_notification_settings_object( const NotificationSettings *notification_settings) { - return make_tl_object(std::max(0, notification_settings->mute_until - G()->unix_time()), + return make_tl_object(max(0, notification_settings->mute_until - G()->unix_time()), notification_settings->sound, notification_settings->show_preview); } @@ -13597,11 +13597,11 @@ void MessagesManager::load_messages(DialogId dialog_id, MessageId from_message_i } if (offset >= -1) { // get history before some server or local message - limit = std::min(std::max(limit + offset + 1, MAX_GET_HISTORY / 2), MAX_GET_HISTORY); + limit = min(max(limit + offset + 1, MAX_GET_HISTORY / 2), MAX_GET_HISTORY); offset = -1; } else { // get history around some server or local message - int32 messages_to_load = std::max(MAX_GET_HISTORY, limit); + int32 messages_to_load = max(MAX_GET_HISTORY, limit); int32 max_add = messages_to_load - limit; offset -= max_add; limit = MAX_GET_HISTORY; @@ -13668,7 +13668,7 @@ tl_object_ptr MessagesManager::get_message_object(DialogId dial can_forward_message(dialog_id, message), can_delete_for_self, can_delete_for_all_users, message->is_channel_post, message->contains_unread_mention, message->date, message->edit_date, get_message_forward_info_object(message->forward_info), message->reply_to_message_id.get(), message->ttl, - message->ttl_expires_at != 0 ? std::max(message->ttl_expires_at - Time::now(), 1e-3) : message->ttl, + message->ttl_expires_at != 0 ? max(message->ttl_expires_at - Time::now(), 1e-3) : message->ttl, td_->contacts_manager_->get_user_id_object(message->via_bot_user_id, "via_bot_user_id"), message->author_signature, message->views, message->media_album_id, get_message_content_object(message->content.get()), get_reply_markup_object(message->reply_markup)); @@ -14439,7 +14439,7 @@ MessagesManager::Message *MessagesManager::get_message_to_send(Dialog *d, Messag m->ttl = 0; } if (m->ttl > 0) { - m->ttl = std::max(m->ttl, get_message_content_duration(m->content.get()) + 1); + m->ttl = max(m->ttl, get_message_content_duration(m->content.get()) + 1); } if (reply_to_message_id.is_valid()) { auto *reply_to_message = get_message_force(d, reply_to_message_id); @@ -24333,6 +24333,4 @@ void MessagesManager::get_payment_receipt(FullMessageId full_message_id, td::get_payment_receipt(message_id.get_server_message_id(), std::move(promise)); } -constexpr int32 MessagesManager::MAX_GET_HISTORY; - } // namespace td diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 3b8361e3b..659df639e 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1783,7 +1783,7 @@ vector StickersManager::get_stickers(string emoji, int32 limit, bool for } vector sorted; - sorted.reserve(std::min(limit_size_t, result.size())); + sorted.reserve(min(limit_size_t, result.size())); for (auto &sticker_id : prepend_sticker_ids) { bool is_good = false; auto it = std::find(result.begin(), result.end(), sticker_id); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 765e556c4..98a2b7299 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -78,7 +78,6 @@ #include "td/utils/tl_parsers.h" #include "td/utils/utf8.h" -#include #include #include #include @@ -4212,7 +4211,7 @@ Status Td::init(DbKey key) { TdDb::Events events; TRY_RESULT(td_db, - TdDb::open(std::min(current_scheduler_id + 1, scheduler_count - 1), parameters_, std::move(key), events)); + TdDb::open(min(current_scheduler_id + 1, scheduler_count - 1), parameters_, std::move(key), events)); LOG(INFO) << "Successfully inited database in " << tag("database_directory", parameters_.database_directory) << " and " << tag("files_directory", parameters_.files_directory); G()->init(parameters_, actor_id(this), std::move(td_db)).ensure(); @@ -4339,7 +4338,7 @@ Status Td::init(DbKey key) { secret_chats_manager_ = create_actor("SecretChatsManager", create_reference()); G()->set_secret_chats_manager(secret_chats_manager_.get()); storage_manager_ = create_actor("StorageManager", create_reference(), - std::min(current_scheduler_id + 2, scheduler_count - 1)); + min(current_scheduler_id + 2, scheduler_count - 1)); G()->set_storage_manager(storage_manager_.get()); top_dialog_manager_ = create_actor("TopDialogManager", create_reference()); G()->set_top_dialog_manager(top_dialog_manager_.get()); @@ -6313,7 +6312,7 @@ void Td::on_request(uint64 id, td_api::setOption &request) { << min << ", " << max << "]"); return true; } - G()->shared_config().set_option_integer(name, std::max(std::min(value, max), min)); + G()->shared_config().set_option_integer(name, clamp(value, min, max)); } send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); return true; diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index 8eefbfccd..8fa0510b3 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -33,8 +33,6 @@ namespace td { -constexpr size_t TopDialogManager::MAX_TOP_DIALOGS_LIMIT; - static CSlice top_dialog_category_name(TopDialogCategory category) { switch (category) { case TopDialogCategory::Correspondent: @@ -235,9 +233,9 @@ void TopDialogManager::do_get_top_dialogs(GetTopDialogsQuery &&query) { CHECK(pos < by_category_.size()); auto &top_dialogs = by_category_[pos]; - auto limit = std::min(query.limit, MAX_TOP_DIALOGS_LIMIT); + auto limit = min(query.limit, MAX_TOP_DIALOGS_LIMIT); - limit = std::min(limit, top_dialogs.dialogs.size()); + limit = min(limit, top_dialogs.dialogs.size()); vector dialog_ids = transform(top_dialogs.dialogs, [](const auto &x) { return x.dialog_id; }); auto promise = PromiseCreator::lambda([query = std::move(query), dialog_ids, limit](Result) mutable { diff --git a/td/telegram/VideoNotesManager.cpp b/td/telegram/VideoNotesManager.cpp index 8807a1481..42c4c30d4 100644 --- a/td/telegram/VideoNotesManager.cpp +++ b/td/telegram/VideoNotesManager.cpp @@ -21,8 +21,6 @@ #include "td/utils/misc.h" #include "td/utils/Status.h" -#include - namespace td { VideoNotesManager::VideoNotesManager(Td *td) : td_(td) { @@ -151,7 +149,7 @@ void VideoNotesManager::create_video_note(FileId file_id, PhotoSize thumbnail, i bool replace) { auto v = make_unique(); v->file_id = file_id; - v->duration = std::max(duration, 0); + v->duration = max(duration, 0); if (dimensions.width == dimensions.height && dimensions.width <= 640) { v->dimensions = dimensions; } else { diff --git a/td/telegram/VideosManager.cpp b/td/telegram/VideosManager.cpp index 1878e233a..3b0a0e3cb 100644 --- a/td/telegram/VideosManager.cpp +++ b/td/telegram/VideosManager.cpp @@ -22,8 +22,6 @@ #include "td/utils/misc.h" #include "td/utils/Status.h" -#include - namespace td { VideosManager::VideosManager(Td *td) : td_(td) { @@ -182,7 +180,7 @@ void VideosManager::create_video(FileId file_id, PhotoSize thumbnail, bool has_s v->file_id = file_id; v->file_name = std::move(file_name); v->mime_type = std::move(mime_type); - v->duration = std::max(duration, 0); + v->duration = max(duration, 0); v->dimensions = dimensions; v->thumbnail = std::move(thumbnail); v->supports_streaming = supports_streaming; diff --git a/td/telegram/VoiceNotesManager.cpp b/td/telegram/VoiceNotesManager.cpp index ad1ee6253..74b4c4328 100644 --- a/td/telegram/VoiceNotesManager.cpp +++ b/td/telegram/VoiceNotesManager.cpp @@ -22,8 +22,6 @@ #include "td/utils/misc.h" #include "td/utils/Status.h" -#include - namespace td { VoiceNotesManager::VoiceNotesManager(Td *td) : td_(td) { @@ -136,7 +134,7 @@ void VoiceNotesManager::create_voice_note(FileId file_id, string mime_type, int3 auto v = std::make_unique(); v->file_id = file_id; v->mime_type = std::move(mime_type); - v->duration = std::max(duration, 0); + v->duration = max(duration, 0); v->waveform = std::move(waveform); on_get_voice_note(std::move(v), replace); } diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 529be5036..5d0182ea9 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -45,7 +45,6 @@ #include "td/utils/StringBuilder.h" #include "td/utils/tl_helpers.h" -#include #include namespace td { @@ -544,7 +543,7 @@ class WebPagesManager::PageBlockAuthorDate : public PageBlock { public: PageBlockAuthorDate() = default; - PageBlockAuthorDate(RichText &&author, int32 date) : author(std::move(author)), date(std::max(date, 0)) { + PageBlockAuthorDate(RichText &&author, int32 date) : author(std::move(author)), date(max(date, 0)) { } Type get_type() const override { @@ -1125,7 +1124,7 @@ class WebPagesManager::PageBlockEmbeddedPost : public PageBlock { : url(std::move(url)) , author(std::move(author)) , author_photo(std::move(author_photo)) - , date(std::max(date, 0)) + , date(max(date, 0)) , page_blocks(std::move(page_blocks)) , caption(std::move(caption)) { } @@ -1439,7 +1438,7 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr auto web_page_date = web_page->date_; LOG(INFO) << "Got pending " << web_page_id << ", date = " << web_page_date << ", now = " << G()->server_time(); - pending_web_pages_timeout_.add_timeout_in(web_page_id.get(), std::max(web_page_date - G()->server_time(), 1.0)); + pending_web_pages_timeout_.add_timeout_in(web_page_id.get(), max(web_page_date - G()->server_time(), 1.0)); return web_page_id; } case telegram_api::webPage::ID: { diff --git a/td/telegram/files/FileDownloader.cpp b/td/telegram/files/FileDownloader.cpp index 753b091d2..4d6237d66 100644 --- a/td/telegram/files/FileDownloader.cpp +++ b/td/telegram/files/FileDownloader.cpp @@ -21,7 +21,6 @@ #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" -#include #include namespace td { @@ -171,7 +170,7 @@ Result> FileDownloader::start_part(Part part, int32 // auto size = part.size; //// sometimes we can ask more than server has, just to check size // if (size < get_part_size()) { - // size = std::min(size + 16, get_part_size()); + // size = min(size + 16, get_part_size()); // LOG(INFO) << "Ask " << size << " instead of " << part.size; //} auto size = get_part_size(); diff --git a/td/telegram/files/FileLoader.cpp b/td/telegram/files/FileLoader.cpp index 3529fb5e5..242990935 100644 --- a/td/telegram/files/FileLoader.cpp +++ b/td/telegram/files/FileLoader.cpp @@ -17,7 +17,6 @@ #include "td/utils/misc.h" #include "td/utils/ScopeGuard.h" -#include #include namespace td { @@ -73,7 +72,7 @@ void FileLoader::start_up() { } auto file_info = r_file_info.ok(); auto size = file_info.size; - auto expected_size = std::max(size, file_info.expected_size); + auto expected_size = max(size, file_info.expected_size); bool is_size_final = file_info.is_size_final; auto part_size = file_info.part_size; auto &ready_parts = file_info.ready_parts; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 2a38dbe8f..6bb1538ea 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -164,7 +164,7 @@ void FileNode::set_generate_priority(int8 download_priority, int8 upload_priorit << upload_priority; on_info_changed(); } - generate_priority_ = std::max(download_priority, upload_priority); + generate_priority_ = max(download_priority, upload_priority); generate_download_priority_ = download_priority; generate_upload_priority_ = upload_priority; } @@ -282,9 +282,8 @@ int64 FileView::local_total_size() const { case LocalFileLocation::Type::Full: return node_->size_; case LocalFileLocation::Type::Partial: - return std::max( - static_cast(node_->local_.partial().part_size_) * node_->local_.partial().ready_part_count_, - node_->local_ready_size_); + return max(static_cast(node_->local_.partial().part_size_) * node_->local_.partial().ready_part_count_, + node_->local_ready_size_); default: UNREACHABLE(); return 0; @@ -301,8 +300,8 @@ int64 FileView::remote_size() const { return node_->size_; case RemoteFileLocation::Type::Partial: { auto res = - std::max(static_cast(node_->remote_.partial().part_size_) * node_->remote_.partial().ready_part_count_, - node_->remote_ready_size_); + max(static_cast(node_->remote_.partial().part_size_) * node_->remote_.partial().ready_part_count_, + node_->remote_ready_size_); if (size() != 0 && size() < res) { res = size(); } diff --git a/td/telegram/files/PartsManager.cpp b/td/telegram/files/PartsManager.cpp index 47e85dc2a..75debb7af 100644 --- a/td/telegram/files/PartsManager.cpp +++ b/td/telegram/files/PartsManager.cpp @@ -10,7 +10,6 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" -#include #include #include @@ -53,8 +52,8 @@ Status PartsManager::init_no_size(size_t part_size, const std::vector &read if (known_prefix_flag_) { part_count_ = static_cast(known_prefix_size_ / part_size_); } - part_count_ = std::max(part_count_, std::accumulate(ready_parts.begin(), ready_parts.end(), 0, - [](auto a, auto b) { return std::max(a, b + 1); })); + part_count_ = max(part_count_, std::accumulate(ready_parts.begin(), ready_parts.end(), 0, + [](auto a, auto b) { return max(a, b + 1); })); init_common(ready_parts); return Status::OK(); @@ -169,7 +168,7 @@ Status PartsManager::set_known_prefix(size_t size, bool is_ready) { CHECK(known_prefix_flag_); CHECK(size >= static_cast(known_prefix_size_)); known_prefix_size_ = narrow_cast(size); - expected_size_ = std::max(known_prefix_size_, expected_size_); + expected_size_ = max(known_prefix_size_, expected_size_); CHECK(static_cast(part_count_) == part_status_.size()); if (is_ready) { @@ -203,10 +202,10 @@ Status PartsManager::on_part_ok(int32 id, size_t part_size, size_t actual_size) if (unknown_size_flag_) { CHECK(part_size == part_size_); if (actual_size < part_size_) { - max_size_ = std::min(max_size_, end_offset); + max_size_ = min(max_size_, end_offset); } if (actual_size) { - min_size_ = std::max(min_size_, end_offset); + min_size_ = max(min_size_, end_offset); } if (min_size_ > max_size_) { auto status = Status::Error(PSLICE() << "Failed to transfer file: " << tag("min_size", min_size_) @@ -251,7 +250,7 @@ int64 PartsManager::get_ready_size() const { int64 PartsManager::get_expected_size() const { if (unknown_size_flag_) { - return std::max(static_cast(512 * (1 << 10)), get_ready_size() * 2); + return max(static_cast(512 * (1 << 10)), get_ready_size() * 2); } return get_size(); } @@ -302,7 +301,7 @@ int64 PartsManager::get_unchecked_ready_prefix_size() { int64 res = part.offset; if (!unknown_size_flag_) { res += narrow_cast(part.size); - res = std::min(res, get_size()); + res = min(res, get_size()); } return res; } @@ -315,7 +314,7 @@ Part PartsManager::get_part(int id) { if (total_size < offset) { size = 0; } else { - size = std::min(size, total_size - offset); + size = min(size, total_size - offset); } } return Part{id, offset, static_cast(size)}; diff --git a/td/telegram/files/ResourceManager.cpp b/td/telegram/files/ResourceManager.cpp index 63afa26a3..00677ddd7 100644 --- a/td/telegram/files/ResourceManager.cpp +++ b/td/telegram/files/ResourceManager.cpp @@ -111,7 +111,7 @@ bool ResourceManager::satisfy_node(NodeId file_node_id) { return true; } auto give = resource_state_.unused(); - give = std::min(need, give); + give = min(need, give); give -= give % part_size; VLOG(files) << tag("give", give); if (give == 0) { diff --git a/td/telegram/files/ResourceState.h b/td/telegram/files/ResourceState.h index 3819dd3b5..e6a251ce9 100644 --- a/td/telegram/files/ResourceState.h +++ b/td/telegram/files/ResourceState.h @@ -11,8 +11,6 @@ #include "td/utils/logging.h" #include "td/utils/StringBuilder.h" -#include - namespace td { class ResourceState { @@ -58,7 +56,7 @@ class ResourceState { } int64 estimated_extra() const { - auto new_unused = std::max(limit_, estimated_limit_) - using_ - used_; + auto new_unused = max(limit_, estimated_limit_) - using_ - used_; new_unused = static_cast((new_unused + unit_size() - 1) / unit_size() * unit_size()); return new_unused + using_ + used_ - limit_; } diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 90c971832..1bc3a3d9b 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -352,9 +352,9 @@ void ConnectionCreator::client_loop(ClientInfo &client) { // Check flood auto &flood_control = online_flag_ ? client.flood_control_online : client.flood_control; - auto wakeup_at = std::max(flood_control.get_wakeup_at(), client.mtproto_error_flood_control.get_wakeup_at()); + auto wakeup_at = max(flood_control.get_wakeup_at(), client.mtproto_error_flood_control.get_wakeup_at()); if (!online_flag_) { - wakeup_at = std::max(wakeup_at, client.backoff.get_wakeup_at()); + wakeup_at = max(wakeup_at, client.backoff.get_wakeup_at()); } if (wakeup_at > Time::now()) { return client_set_timeout_at(client, wakeup_at); @@ -691,6 +691,4 @@ void ConnectionCreator::on_proxy_resolved(Result r_ip_address, bool d } } -constexpr int32 ConnectionCreator::ClientInfo::Backoff::MAX_BACKOFF; - } // namespace td diff --git a/td/telegram/net/ConnectionCreator.h b/td/telegram/net/ConnectionCreator.h index 895865556..676a1d165 100644 --- a/td/telegram/net/ConnectionCreator.h +++ b/td/telegram/net/ConnectionCreator.h @@ -26,7 +26,6 @@ #include "td/utils/Status.h" #include "td/utils/Time.h" -#include #include #include #include @@ -161,7 +160,7 @@ class ConnectionCreator : public Actor { public: void add_event(int32 now) { wakeup_at_ = now + next_delay_; - next_delay_ = std::min(MAX_BACKOFF, next_delay_ * 2); + next_delay_ = min(MAX_BACKOFF, next_delay_ * 2); } int32 get_wakeup_at() const { return wakeup_at_; diff --git a/td/telegram/net/NetQueryDispatcher.cpp b/td/telegram/net/NetQueryDispatcher.cpp index 52b98e981..1ea925d3c 100644 --- a/td/telegram/net/NetQueryDispatcher.cpp +++ b/td/telegram/net/NetQueryDispatcher.cpp @@ -25,8 +25,6 @@ #include "td/utils/port/thread.h" #include "td/utils/Slice.h" -#include - namespace td { void NetQueryDispatcher::dispatch(NetQueryPtr net_query) { net_query->debug("dispatch"); @@ -231,7 +229,7 @@ bool NetQueryDispatcher::is_dc_inited(int32 raw_dc_id) { return dcs_[raw_dc_id - 1].is_valid_.load(std::memory_order_relaxed); } int32 NetQueryDispatcher::get_session_count() { - return std::max(G()->shared_config().get_option_integer("session_count"), 1); + return max(G()->shared_config().get_option_integer("session_count"), 1); } bool NetQueryDispatcher::get_use_pfs() { diff --git a/td/telegram/net/TempAuthKeyWatchdog.h b/td/telegram/net/TempAuthKeyWatchdog.h index 0cd97ef42..eff190bf6 100644 --- a/td/telegram/net/TempAuthKeyWatchdog.h +++ b/td/telegram/net/TempAuthKeyWatchdog.h @@ -19,7 +19,6 @@ #include "td/utils/logging.h" #include "td/utils/Time.h" -#include #include namespace td { @@ -89,7 +88,7 @@ class TempAuthKeyWatchdog : public NetQueryCallback { sync_at_ = now + SYNC_WAIT_MAX; } LOG(DEBUG) << "set timeout"; - set_timeout_at(std::min(sync_at_, now + SYNC_WAIT)); + set_timeout_at(min(sync_at_, now + SYNC_WAIT)); } void timeout_expired() override { diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp index d4b178314..675c78f52 100644 --- a/tddb/td/db/binlog/Binlog.cpp +++ b/tddb/td/db/binlog/Binlog.cpp @@ -24,8 +24,6 @@ #include "td/utils/tl_helpers.h" #include "td/utils/tl_parsers.h" -#include - namespace td { namespace detail { struct AesCtrEncryptionEvent { @@ -465,7 +463,7 @@ Status Binlog::load_binlog(const Callback &callback, const Callback &debug_callb if (ready_flag) { break; } - TRY_STATUS(fd_.flush_read(std::max(need_size, static_cast(4096)))); + TRY_STATUS(fd_.flush_read(max(need_size, static_cast(4096)))); buffer_reader_.sync_with_writer(); if (byte_flow_flag_) { byte_flow_source_.wakeup(); diff --git a/tdnet/td/net/HttpChunkedByteFlow.cpp b/tdnet/td/net/HttpChunkedByteFlow.cpp index 1fdb442e4..2edd225bf 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.cpp +++ b/tdnet/td/net/HttpChunkedByteFlow.cpp @@ -12,9 +12,8 @@ #include "td/utils/misc.h" #include "td/utils/Status.h" -#include - namespace td { + void HttpChunkedByteFlow::loop() { bool was_updated = false; size_t need_size; @@ -40,8 +39,8 @@ void HttpChunkedByteFlow::loop() { } auto size = input_->size(); - auto ready = std::min(len_, size); - need_size = std::min(MIN_UPDATE_SIZE, len_ + 2); + auto ready = min(len_, size); + need_size = min(MIN_UPDATE_SIZE, len_ + 2); if (size < need_size) { break; } @@ -80,5 +79,5 @@ void HttpChunkedByteFlow::loop() { } set_need_size(need_size); } -constexpr size_t HttpChunkedByteFlow::MIN_UPDATE_SIZE; + } // namespace td diff --git a/tdnet/td/net/HttpContentLengthByteFlow.cpp b/tdnet/td/net/HttpContentLengthByteFlow.cpp index 6fef3ff17..ea299b399 100644 --- a/tdnet/td/net/HttpContentLengthByteFlow.cpp +++ b/tdnet/td/net/HttpContentLengthByteFlow.cpp @@ -8,8 +8,6 @@ #include "td/utils/Status.h" -#include - namespace td { void HttpContentLengthByteFlow::loop() { @@ -17,7 +15,7 @@ void HttpContentLengthByteFlow::loop() { if (ready_size > len_) { ready_size = len_; } - auto need_size = std::min(MIN_UPDATE_SIZE, len_); + auto need_size = min(MIN_UPDATE_SIZE, len_); if (ready_size < need_size) { set_need_size(need_size); return; @@ -32,6 +30,5 @@ void HttpContentLengthByteFlow::loop() { } on_output_updated(); } -constexpr size_t HttpContentLengthByteFlow::MIN_UPDATE_SIZE; } // namespace td diff --git a/tdutils/td/utils/BufferedReader.h b/tdutils/td/utils/BufferedReader.h index 28431cbf4..9006d7813 100644 --- a/tdutils/td/utils/BufferedReader.h +++ b/tdutils/td/utils/BufferedReader.h @@ -11,7 +11,6 @@ #include "td/utils/Slice.h" #include "td/utils/Status.h" -#include #include namespace td { @@ -54,7 +53,7 @@ inline Result BufferedReader::read(MutableSlice slice) { begin_pos_ = 0; end_pos_ = result; - size_t left = std::min(end_pos_, slice.size()); + size_t left = min(end_pos_, slice.size()); std::memcpy(slice.begin(), &buff_[begin_pos_], left); begin_pos_ += left; return left + available; diff --git a/tdutils/td/utils/FloodControlFast.h b/tdutils/td/utils/FloodControlFast.h index b09d64864..9f047881a 100644 --- a/tdutils/td/utils/FloodControlFast.h +++ b/tdutils/td/utils/FloodControlFast.h @@ -9,8 +9,6 @@ #include "td/utils/common.h" #include "td/utils/TimedStat.h" -#include - namespace td { class FloodControlFast { @@ -19,7 +17,7 @@ class FloodControlFast { for (auto &limit : limits_) { limit.stat_.add_event(CounterStat::Event(), now); if (limit.stat_.get_stat(now).count_ > limit.count_) { - wakeup_at_ = std::max(wakeup_at_, now + limit.duration_ * 2); + wakeup_at_ = max(wakeup_at_, now + limit.duration_ * 2); } } return wakeup_at_; diff --git a/tdutils/td/utils/FloodControlStrict.h b/tdutils/td/utils/FloodControlStrict.h index 924fd1013..521fbbedc 100644 --- a/tdutils/td/utils/FloodControlStrict.h +++ b/tdutils/td/utils/FloodControlStrict.h @@ -9,7 +9,6 @@ #include "td/utils/common.h" #include "td/utils/logging.h" -#include #include namespace td { @@ -62,13 +61,13 @@ class FloodControlStrict { if (limit.count_ + limit.pos_ <= events_.size()) { CHECK(limit.count_ + limit.pos_ == events_.size()); - wakeup_at_ = std::max(wakeup_at_, events_[limit.pos_].timestamp_ + limit.duration_); + wakeup_at_ = max(wakeup_at_, events_[limit.pos_].timestamp_ + limit.duration_); without_update_ = 0; } else { - without_update_ = std::min(without_update_, limit.count_ + limit.pos_ - events_.size()); + without_update_ = min(without_update_, limit.count_ + limit.pos_ - events_.size()); } - min_pos = std::min(min_pos, limit.pos_); + min_pos = min(min_pos, limit.pos_); } if (min_pos * 2 > events_.size()) { diff --git a/tdutils/td/utils/Heap.h b/tdutils/td/utils/Heap.h index 5ae7405c1..54ee39149 100644 --- a/tdutils/td/utils/Heap.h +++ b/tdutils/td/utils/Heap.h @@ -9,8 +9,6 @@ #include "td/utils/common.h" #include "td/utils/logging.h" -#include - namespace td { struct HeapNode { @@ -119,7 +117,7 @@ class KHeap { auto item = array_[pos]; while (true) { int left_pos = pos * K + 1; - int right_pos = std::min(left_pos + K, static_cast(array_.size())); + int right_pos = min(left_pos + K, static_cast(array_.size())); int next_pos = pos; KeyT next_key = item.key_; for (int i = left_pos; i < right_pos; i++) { diff --git a/tdutils/td/utils/Random.cpp b/tdutils/td/utils/Random.cpp index 7e797e5b1..db11df4df 100644 --- a/tdutils/td/utils/Random.cpp +++ b/tdutils/td/utils/Random.cpp @@ -13,7 +13,6 @@ #include #endif -#include #include #include #include @@ -33,7 +32,7 @@ void Random::secure_bytes(unsigned char *ptr, size_t size) { buf_pos = buf_size; } - auto ready = std::min(size, buf_size - buf_pos); + auto ready = min(size, buf_size - buf_pos); if (ready != 0) { std::memcpy(ptr, buf + buf_pos, ready); buf_pos += ready; diff --git a/tdutils/td/utils/Slice.h b/tdutils/td/utils/Slice.h index b25b1ae64..a9bc6a755 100644 --- a/tdutils/td/utils/Slice.h +++ b/tdutils/td/utils/Slice.h @@ -10,7 +10,6 @@ #include "td/utils/logging.h" -#include #include namespace td { @@ -96,7 +95,7 @@ inline MutableSlice MutableSlice::substr(size_t from) const { } inline MutableSlice MutableSlice::substr(size_t from, size_t size) const { CHECK(from <= len_); - return MutableSlice(s_ + from, std::min(size, len_ - from)); + return MutableSlice(s_ + from, min(size, len_ - from)); } inline size_t MutableSlice::find(char c) const { @@ -217,7 +216,7 @@ inline Slice Slice::substr(size_t from) const { } inline Slice Slice::substr(size_t from, size_t size) const { CHECK(from <= len_); - return Slice(s_ + from, std::min(size, len_ - from)); + return Slice(s_ + from, min(size, len_ - from)); } inline size_t Slice::find(char c) const { diff --git a/tdutils/td/utils/base64.cpp b/tdutils/td/utils/base64.cpp index 89454bee6..4016feaa5 100644 --- a/tdutils/td/utils/base64.cpp +++ b/tdutils/td/utils/base64.cpp @@ -23,7 +23,7 @@ string base64_encode(Slice input) { string base64; base64.reserve((input.size() + 2) / 3 * 4); for (size_t i = 0; i < input.size();) { - size_t left = std::min(input.size() - i, static_cast(3)); + size_t left = min(input.size() - i, static_cast(3)); int c = input.ubegin()[i++] << 16; base64 += symbols64[c >> 18]; if (left != 1) { @@ -78,7 +78,7 @@ Result base64_decode(Slice base64) { string output; output.reserve(((base64.size() + 3) >> 2) * 3); for (size_t i = 0; i < base64.size();) { - size_t left = std::min(base64.size() - i, static_cast(4)); + size_t left = min(base64.size() - i, static_cast(4)); int c = 0; for (size_t t = 0; t < left; t++) { auto value = char_to_value[base64.ubegin()[i++]]; @@ -112,7 +112,7 @@ string base64url_encode(Slice input) { string base64; base64.reserve((input.size() + 2) / 3 * 4); for (size_t i = 0; i < input.size();) { - size_t left = std::min(input.size() - i, static_cast(3)); + size_t left = min(input.size() - i, static_cast(3)); int c = input.ubegin()[i++] << 16; base64 += url_symbols64[c >> 18]; if (left != 1) { @@ -163,7 +163,7 @@ Result base64url_decode(Slice base64) { string output; output.reserve(((base64.size() + 3) >> 2) * 3); for (size_t i = 0; i < base64.size();) { - size_t left = std::min(base64.size() - i, static_cast(4)); + size_t left = min(base64.size() - i, static_cast(4)); int c = 0; for (size_t t = 0; t < left; t++) { auto value = url_char_to_value[base64.ubegin()[i++]]; diff --git a/tdutils/td/utils/buffer.cpp b/tdutils/td/utils/buffer.cpp index fa5f63224..c1a123031 100644 --- a/tdutils/td/utils/buffer.cpp +++ b/tdutils/td/utils/buffer.cpp @@ -76,7 +76,7 @@ BufferAllocator::ReaderPtr BufferAllocator::create_reader(const ReaderPtr &raw) void BufferAllocator::dec_ref_cnt(BufferRaw *ptr) { int left = ptr->ref_cnt_.fetch_sub(1, std::memory_order_acq_rel); if (left == 1) { - auto buf_size = std::max(sizeof(BufferRaw), offsetof(BufferRaw, data_) + ptr->data_size_); + auto buf_size = max(sizeof(BufferRaw), offsetof(BufferRaw, data_) + ptr->data_size_); buffer_mem -= buf_size; ptr->~BufferRaw(); delete[] ptr; diff --git a/tdutils/td/utils/buffer.h b/tdutils/td/utils/buffer.h index e5a8d1181..729cd20f7 100644 --- a/tdutils/td/utils/buffer.h +++ b/tdutils/td/utils/buffer.h @@ -11,7 +11,6 @@ #include "td/utils/port/thread_local.h" #include "td/utils/Slice.h" -#include #include #include #include @@ -470,7 +469,7 @@ class ChainBufferIterator { skipped += ready.size(); // copy to dest if possible - auto to_dest_size = std::min(ready.size(), dest.size()); + auto to_dest_size = min(ready.size(), dest.size()); if (to_dest_size != 0) { std::memcpy(dest.data(), ready.data(), to_dest_size); dest.remove_prefix(to_dest_size); @@ -588,7 +587,7 @@ class ChainBufferReader { } BufferSlice read_as_buffer_slice(size_t limit = std::numeric_limits::max()) { - return begin_.read_as_buffer_slice(std::min(limit, size())); + return begin_.read_as_buffer_slice(min(limit, size())); } private: @@ -649,7 +648,7 @@ class ChainBufferWriter { void append(Slice slice) { while (!slice.empty()) { auto ready = prepare_append(slice.size()); - auto shift = std::min(ready.size(), slice.size()); + auto shift = min(ready.size(), slice.size()); std::memcpy(ready.data(), slice.data(), shift); confirm_append(shift); slice.remove_prefix(shift); diff --git a/tdutils/td/utils/common.h b/tdutils/td/utils/common.h index f7b85b1ef..276460d41 100644 --- a/tdutils/td/utils/common.h +++ b/tdutils/td/utils/common.h @@ -82,6 +82,18 @@ inline bool unlikely(bool x) { #endif } +// replace std::max and std::min to not have to include everywhere +// as a side bonus, accept parameters by value, so constexpr variables aren't required to be instantiated +template +T max(T a, T b) { + return a < b ? b : a; +} + +template +T min(T a, T b) { + return a > b ? b : a; +} + using string = std::string; template diff --git a/tdutils/td/utils/crypto.cpp b/tdutils/td/utils/crypto.cpp index 312764fcf..3e54e673a 100644 --- a/tdutils/td/utils/crypto.cpp +++ b/tdutils/td/utils/crypto.cpp @@ -73,7 +73,7 @@ uint64 pq_factorize(uint64 pq) { uint64 q = Random::fast(17, 32) % (pq - 1); uint64 x = Random::fast_uint64() % (pq - 1) + 1; uint64 y = x; - int lim = 1 << (std::min(5, i) + 18); + int lim = 1 << (min(5, i) + 18); for (int j = 1; j < lim; j++) { it++; uint64 a = x; diff --git a/tdutils/td/utils/misc.h b/tdutils/td/utils/misc.h index 9c397de5f..62b01794a 100644 --- a/tdutils/td/utils/misc.h +++ b/tdutils/td/utils/misc.h @@ -96,7 +96,7 @@ auto append(vector &destination, vector &&source) { return; } destination.reserve(destination.size() + source.size()); - for (auto &elem:source) { + for (auto &elem : source) { destination.push_back(std::move(elem)); } reset_to_empty(source); diff --git a/tdutils/td/utils/port/Fd.cpp b/tdutils/td/utils/port/Fd.cpp index a7fb51efe..cb4cb2730 100644 --- a/tdutils/td/utils/port/Fd.cpp +++ b/tdutils/td/utils/port/Fd.cpp @@ -28,7 +28,6 @@ #include "td/utils/buffer.h" #include "td/utils/misc.h" -#include #include #endif @@ -555,7 +554,7 @@ class Fd::FdImpl { } Result read_async(MutableSlice slice) TD_WARN_UNUSED_RESULT { CHECK(async_mode_); - auto res = input_reader_.advance(std::min(slice.size(), input_reader_.size()), slice); + auto res = input_reader_.advance(min(slice.size(), input_reader_.size()), slice); if (res == 0) { clear_flags(Fd::Flag::Read); }