From 3442a88413643f1e0321f036489849e96d30e78b Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 16 Jun 2020 05:10:16 +0300 Subject: [PATCH] Unify constant names style. GitOrigin-RevId: 6e4475366b94cea6ab0331d57f254311490bdee2 --- memprof/memprof.cpp | 26 +++++++++++++------------- td/telegram/RequestActor.h | 2 +- td/telegram/logevent/SecretChatEvent.h | 12 ++++++------ td/telegram/net/NetStatsManager.cpp | 4 ++-- td/telegram/net/NetStatsManager.h | 4 ++-- tdactor/td/actor/PromiseFuture.h | 4 ++-- tddb/td/db/BinlogKeyValue.h | 4 ++-- tdutils/td/utils/StringBuilder.cpp | 22 +++++++++++----------- tdutils/td/utils/StringBuilder.h | 6 +++--- tdutils/td/utils/port/UdpSocketFd.cpp | 4 ++-- tdutils/td/utils/port/UdpSocketFd.h | 4 ++-- tdutils/test/ConcurrentHashMap.cpp | 6 +++--- 12 files changed, 49 insertions(+), 49 deletions(-) diff --git a/memprof/memprof.cpp b/memprof/memprof.cpp index dc0bac7f3..a4ee97ce1 100644 --- a/memprof/memprof.cpp +++ b/memprof/memprof.cpp @@ -117,8 +117,8 @@ static Backtrace get_backtrace() { return res; } -static constexpr std::size_t reserved = 16; -static constexpr std::int32_t malloc_info_magic = 0x27138373; +static constexpr std::size_t RESERVED_SIZE = 16; +static constexpr std::int32_t MALLOC_INFO_MAGIC = 0x27138373; struct malloc_info { std::int32_t magic; std::int32_t size; @@ -139,9 +139,9 @@ struct HashtableNode { std::atomic size; }; -static constexpr std::size_t ht_max_size = 1000000; +static constexpr std::size_t HT_MAX_SIZE = 1000000; static std::atomic ht_size{0}; -static std::array ht; +static std::array ht; std::size_t get_ht_size() { return ht_size.load(); @@ -154,9 +154,9 @@ std::int32_t get_ht_pos(const Backtrace &bt, bool force = false) { while (true) { auto pos_hash = ht[pos].hash.load(); if (pos_hash == 0) { - if (ht_size > ht_max_size / 2) { + if (ht_size > HT_MAX_SIZE / 2) { if (force) { - assert(ht_size * 10 < ht_max_size * 7); + assert(ht_size * 10 < HT_MAX_SIZE * 7); } else { Backtrace unknown_bt{{nullptr}}; unknown_bt[0] = reinterpret_cast(1); @@ -206,8 +206,8 @@ void register_xalloc(malloc_info *info, std::int32_t diff) { extern "C" { static void *malloc_with_frame(std::size_t size, const Backtrace &frame) { - static_assert(reserved % alignof(std::max_align_t) == 0, "fail"); - static_assert(reserved >= sizeof(malloc_info), "fail"); + static_assert(RESERVED_SIZE % alignof(std::max_align_t) == 0, "fail"); + static_assert(RESERVED_SIZE >= sizeof(malloc_info), "fail"); #if TD_DARWIN static void *malloc_void = dlsym(RTLD_NEXT, "malloc"); static auto malloc_old = *reinterpret_cast(&malloc_void); @@ -215,26 +215,26 @@ static void *malloc_with_frame(std::size_t size, const Backtrace &frame) { extern decltype(malloc) __libc_malloc; static auto malloc_old = __libc_malloc; #endif - auto *info = static_cast(malloc_old(size + reserved)); + auto *info = static_cast(malloc_old(size + RESERVED_SIZE)); auto *buf = reinterpret_cast(info); - info->magic = malloc_info_magic; + info->magic = MALLOC_INFO_MAGIC; info->size = static_cast(size); info->ht_pos = get_ht_pos(frame); register_xalloc(info, +1); - void *data = buf + reserved; + void *data = buf + RESERVED_SIZE; return data; } static malloc_info *get_info(void *data_void) { char *data = static_cast(data_void); - auto *buf = data - reserved; + auto *buf = data - RESERVED_SIZE; auto *info = reinterpret_cast(buf); - assert(info->magic == malloc_info_magic); + assert(info->magic == MALLOC_INFO_MAGIC); return info; } diff --git a/td/telegram/RequestActor.h b/td/telegram/RequestActor.h index f80d06982..cec5f8240 100644 --- a/td/telegram/RequestActor.h +++ b/td/telegram/RequestActor.h @@ -63,7 +63,7 @@ class RequestActor : public Actor { void raw_event(const Event::Raw &event) override { if (future_.is_error()) { auto error = future_.move_as_error(); - if (error == Status::Error::Hangup>()) { + if (error == Status::Error::HANGUP_ERROR_CODE>()) { // dropping query due to lost authorization or lost promise // td may be already closed, so we should check is auth_manager_ is empty bool is_authorized = td->auth_manager_ && td->auth_manager_->is_authorized(); diff --git a/td/telegram/logevent/SecretChatEvent.h b/td/telegram/logevent/SecretChatEvent.h index 698e4d39b..e0c22e481 100644 --- a/td/telegram/logevent/SecretChatEvent.h +++ b/td/telegram/logevent/SecretChatEvent.h @@ -65,7 +65,7 @@ class SecretChatLogEventBase : public SecretChatEvent { // inputEncryptedFile#5a17b5e5 id:long access_hash:long = InputEncryptedFile; // inputEncryptedFileBigUploaded#2dc173c8 id:long parts:int key_fingerprint:int = InputEncryptedFile; struct EncryptedInputFile { - static constexpr int32 magic = 0x4328d38a; + static constexpr int32 MAGIC = 0x4328d38a; enum Type : int32 { Empty = 0, Uploaded = 1, BigUploaded = 2, Location = 3 } type = Type::Empty; int64 id = 0; int64 access_hash = 0; @@ -75,7 +75,7 @@ struct EncryptedInputFile { template void store(StorerT &storer) const { using td::store; - store(magic, storer); + store(MAGIC, storer); store(type, storer); store(id, storer); store(access_hash, storer); @@ -104,7 +104,7 @@ struct EncryptedInputFile { parse(parts, parser); parse(key_fingerprint, parser); - if (got_magic != magic) { + if (got_magic != MAGIC) { parser.set_error("EncryptedInputFile magic mismatch"); return; } @@ -156,7 +156,7 @@ inline StringBuilder &operator<<(StringBuilder &sb, const EncryptedInputFile &fi // encryptedFile#4a70994c id:long access_hash:long size:int dc_id:int key_fingerprint:int = EncryptedFile; struct EncryptedFileLocation { - static constexpr int32 magic = 0x473d738a; + static constexpr int32 MAGIC = 0x473d738a; int64 id = 0; int64 access_hash = 0; int32 size = 0; @@ -169,7 +169,7 @@ struct EncryptedFileLocation { template void store(StorerT &storer) const { using td::store; - store(magic, storer); + store(MAGIC, storer); store(id, storer); store(access_hash, storer); store(size, storer); @@ -189,7 +189,7 @@ struct EncryptedFileLocation { parse(dc_id, parser); parse(key_fingerprint, parser); - if (got_magic != magic) { + if (got_magic != MAGIC) { parser.set_error("EncryptedFileLocation magic mismatch"); return; } diff --git a/td/telegram/net/NetStatsManager.cpp b/td/telegram/net/NetStatsManager.cpp index 2f2a4b94a..0475947c9 100644 --- a/td/telegram/net/NetStatsManager.cpp +++ b/td/telegram/net/NetStatsManager.cpp @@ -86,7 +86,7 @@ void NetStatsManager::get_network_stats(bool current, Promise prom if (id == 0) { } else if (id == 1) { total = stats; - } else if (id == call_net_stats_id_) { + } else if (id == CALL_NET_STATS_ID) { } else if (file_type != FileType::None) { total_files = total_files + stats; } @@ -109,7 +109,7 @@ void NetStatsManager::get_network_stats(bool current, Promise prom entry.duration = stats.duration; if (id == 0) { result.entries.push_back(std::move(entry)); - } else if (id == call_net_stats_id_) { + } else if (id == CALL_NET_STATS_ID) { entry.is_call = true; result.entries.push_back(std::move(entry)); } else if (file_type != FileType::None) { diff --git a/td/telegram/net/NetStatsManager.h b/td/telegram/net/NetStatsManager.h index d7a6a4cb6..d5bb4e730 100644 --- a/td/telegram/net/NetStatsManager.h +++ b/td/telegram/net/NetStatsManager.h @@ -119,7 +119,7 @@ class NetStatsManager : public Actor { NetStatsInfo media_net_stats_; std::array files_stats_; NetStatsInfo call_net_stats_; - static constexpr int32 call_net_stats_id_{file_type_size + 2}; + static constexpr int32 CALL_NET_STATS_ID{file_type_size + 2}; template void for_each_stat(F &&f) { @@ -130,7 +130,7 @@ class NetStatsManager : public Actor { auto file_type = static_cast(file_type_i); f(stat, file_type_i + 2, get_file_type_name(file_type), file_type); } - f(call_net_stats_, call_net_stats_id_, CSlice("calls"), FileType::None); + f(call_net_stats_, CALL_NET_STATS_ID, CSlice("calls"), FileType::None); } void add_network_stats_impl(NetStatsInfo &info, const NetworkStatsEntry &entry); diff --git a/tdactor/td/actor/PromiseFuture.h b/tdactor/td/actor/PromiseFuture.h index 51e1e56b2..29b21b42b 100644 --- a/tdactor/td/actor/PromiseFuture.h +++ b/tdactor/td/actor/PromiseFuture.h @@ -408,7 +408,7 @@ class FutureActor final : public Actor { public: enum State { Waiting, Ready }; - static constexpr int Hangup = 426487; + static constexpr int HANGUP_ERROR_CODE = 426487; FutureActor() = default; @@ -487,7 +487,7 @@ class FutureActor final : public Actor { } void hangup() override { - set_error(Status::Error()); + set_error(Status::Error()); } void start_up() override { diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h index e976d7f1a..32edf1eed 100644 --- a/tddb/td/db/BinlogKeyValue.h +++ b/tddb/td/db/BinlogKeyValue.h @@ -34,7 +34,7 @@ namespace td { template class BinlogKeyValue : public KeyValueSyncInterface { public: - static constexpr int32 magic = 0x2a280000; + static constexpr int32 MAGIC = 0x2a280000; struct Event : public Storer { Event() = default; @@ -236,7 +236,7 @@ class BinlogKeyValue : public KeyValueSyncInterface { std::unordered_map> map_; std::shared_ptr binlog_; RwMutex rw_mutex_; - int32 magic_ = magic; + int32 magic_ = MAGIC; }; template <> diff --git a/tdutils/td/utils/StringBuilder.cpp b/tdutils/td/utils/StringBuilder.cpp index cf5165902..c8a9a6d16 100644 --- a/tdutils/td/utils/StringBuilder.cpp +++ b/tdutils/td/utils/StringBuilder.cpp @@ -22,14 +22,14 @@ namespace td { StringBuilder::StringBuilder(MutableSlice slice, bool use_buffer) : begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) { - if (slice.size() <= reserved_size) { - auto buffer_size = reserved_size + 100; + if (slice.size() <= RESERVED_SIZE) { + auto buffer_size = RESERVED_SIZE + 100; buffer_ = std::make_unique(buffer_size); begin_ptr_ = buffer_.get(); current_ptr_ = begin_ptr_; - end_ptr_ = begin_ptr_ + buffer_size - reserved_size; + end_ptr_ = begin_ptr_ + buffer_size - RESERVED_SIZE; } else { - end_ptr_ = slice.end() - reserved_size; + end_ptr_ = slice.end() - RESERVED_SIZE; } } @@ -39,7 +39,7 @@ StringBuilder &StringBuilder::operator<<(Slice slice) { if (end_ptr_ < current_ptr_) { return on_error(); } - auto available_size = static_cast(end_ptr_ + reserved_size - 1 - current_ptr_); + auto available_size = static_cast(end_ptr_ + RESERVED_SIZE - 1 - current_ptr_); if (size > available_size) { error_flag_ = true; size = available_size; @@ -101,12 +101,12 @@ bool StringBuilder::reserve_inner(size_t size) { } size_t old_data_size = current_ptr_ - begin_ptr_; - if (size >= std::numeric_limits::max() - reserved_size - old_data_size - 1) { + if (size >= std::numeric_limits::max() - RESERVED_SIZE - old_data_size - 1) { return false; } size_t need_data_size = old_data_size + size; size_t old_buffer_size = end_ptr_ - begin_ptr_; - if (old_buffer_size >= (std::numeric_limits::max() - reserved_size) / 2 - 2) { + if (old_buffer_size >= (std::numeric_limits::max() - RESERVED_SIZE) / 2 - 2) { return false; } size_t new_buffer_size = (old_buffer_size + 1) * 2; @@ -116,13 +116,13 @@ bool StringBuilder::reserve_inner(size_t size) { if (new_buffer_size < 100) { new_buffer_size = 100; } - new_buffer_size += reserved_size; + new_buffer_size += RESERVED_SIZE; auto new_buffer = std::make_unique(new_buffer_size); std::memcpy(new_buffer.get(), begin_ptr_, old_data_size); buffer_ = std::move(new_buffer); begin_ptr_ = buffer_.get(); current_ptr_ = begin_ptr_ + old_data_size; - end_ptr_ = begin_ptr_ + new_buffer_size - reserved_size; + end_ptr_ = begin_ptr_ + new_buffer_size - RESERVED_SIZE; CHECK(end_ptr_ > current_ptr_); CHECK(static_cast(end_ptr_ - current_ptr_) >= size); return true; @@ -193,7 +193,7 @@ StringBuilder &StringBuilder::operator<<(FixedDouble x) { *ss << x.d; int len = narrow_cast(static_cast(ss->tellp())); - auto left = end_ptr_ + reserved_size - current_ptr_; + auto left = end_ptr_ + RESERVED_SIZE - current_ptr_; if (unlikely(len >= left)) { error_flag_ = true; len = left ? narrow_cast(left - 1) : 0; @@ -207,7 +207,7 @@ StringBuilder &StringBuilder::operator<<(const void *ptr) { if (unlikely(!reserve())) { return on_error(); } - current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%p", ptr); + current_ptr_ += std::snprintf(current_ptr_, RESERVED_SIZE, "%p", ptr); return *this; } diff --git a/tdutils/td/utils/StringBuilder.h b/tdutils/td/utils/StringBuilder.h index d2eb461df..c8109d978 100644 --- a/tdutils/td/utils/StringBuilder.h +++ b/tdutils/td/utils/StringBuilder.h @@ -26,7 +26,7 @@ class StringBuilder { } MutableCSlice as_cslice() { - if (current_ptr_ >= end_ptr_ + reserved_size) { + if (current_ptr_ >= end_ptr_ + RESERVED_SIZE) { std::abort(); // shouldn't happen } *current_ptr_ = 0; @@ -104,7 +104,7 @@ class StringBuilder { bool error_flag_ = false; bool use_buffer_ = false; std::unique_ptr buffer_; - static constexpr size_t reserved_size = 30; + static constexpr size_t RESERVED_SIZE = 30; StringBuilder &on_error() { error_flag_ = true; @@ -115,7 +115,7 @@ class StringBuilder { if (end_ptr_ > current_ptr_) { return true; } - return reserve_inner(reserved_size); + return reserve_inner(RESERVED_SIZE); } bool reserve(size_t size) { if (end_ptr_ > current_ptr_ && static_cast(end_ptr_ - current_ptr_) >= size) { diff --git a/tdutils/td/utils/port/UdpSocketFd.cpp b/tdutils/td/utils/port/UdpSocketFd.cpp index bd0efcff2..2f1ef131f 100644 --- a/tdutils/td/utils/port/UdpSocketFd.cpp +++ b/tdutils/td/utils/port/UdpSocketFd.cpp @@ -814,11 +814,11 @@ static Result maximize_buffer(int socket_fd, int optname, uint32 max) { } Result UdpSocketFd::maximize_snd_buffer(uint32 max) { - return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max == 0 ? default_udp_max_snd_buffer_size : max); + return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max == 0 ? DEFAULT_UDP_MAX_SND_BUFFER_SIZE : max); } Result UdpSocketFd::maximize_rcv_buffer(uint32 max) { - return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max == 0 ? default_udp_max_rcv_buffer_size : max); + return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max == 0 ? DEFAULT_UDP_MAX_RCV_BUFFER_SIZE : max); } #else Result UdpSocketFd::maximize_snd_buffer(uint32 max) { diff --git a/tdutils/td/utils/port/UdpSocketFd.h b/tdutils/td/utils/port/UdpSocketFd.h index 952345294..9f92d14de 100644 --- a/tdutils/td/utils/port/UdpSocketFd.h +++ b/tdutils/td/utils/port/UdpSocketFd.h @@ -84,8 +84,8 @@ class UdpSocketFd { #endif private: - static constexpr uint32 default_udp_max_snd_buffer_size = (1 << 24); - static constexpr uint32 default_udp_max_rcv_buffer_size = (1 << 24); + static constexpr uint32 DEFAULT_UDP_MAX_SND_BUFFER_SIZE = (1 << 24); + static constexpr uint32 DEFAULT_UDP_MAX_RCV_BUFFER_SIZE = (1 << 24); std::unique_ptr impl_; explicit UdpSocketFd(unique_ptr impl); }; diff --git a/tdutils/test/ConcurrentHashMap.cpp b/tdutils/test/ConcurrentHashMap.cpp index ff3523a75..0045bff99 100644 --- a/tdutils/test/ConcurrentHashMap.cpp +++ b/tdutils/test/ConcurrentHashMap.cpp @@ -187,7 +187,7 @@ class HashMapBenchmark : public td::Benchmark { size_t threads_n = 16; int mod_; - static constexpr size_t mul_ = 7273; //1000000000 + 7; + static constexpr size_t MUL = 7273; //1000000000 + 7; int n_; public: @@ -211,7 +211,7 @@ class HashMapBenchmark : public td::Benchmark { size_t r = n * (i + 1) / threads_n; threads.emplace_back([l, r, this] { for (size_t i = l; i < r; i++) { - auto x = td::narrow_cast((i + 1) * mul_ % n_) + 3; + auto x = td::narrow_cast((i + 1) * MUL % n_) + 3; auto y = td::narrow_cast(i + 2); hash_map->insert(x, y); } @@ -224,7 +224,7 @@ class HashMapBenchmark : public td::Benchmark { void tear_down() override { for (int i = 0; i < n_; i++) { - auto x = td::narrow_cast((i + 1) * mul_ % n_) + 3; + auto x = td::narrow_cast((i + 1) * MUL % n_) + 3; auto y = td::narrow_cast(i + 2); ASSERT_EQ(y, hash_map->find(x, -1)); }