Unify constant names style.

GitOrigin-RevId: 6e4475366b94cea6ab0331d57f254311490bdee2
This commit is contained in:
levlam 2020-06-16 05:10:16 +03:00
parent 40ee207854
commit 3442a88413
12 changed files with 49 additions and 49 deletions

View File

@ -117,8 +117,8 @@ static Backtrace get_backtrace() {
return res; return res;
} }
static constexpr std::size_t reserved = 16; static constexpr std::size_t RESERVED_SIZE = 16;
static constexpr std::int32_t malloc_info_magic = 0x27138373; static constexpr std::int32_t MALLOC_INFO_MAGIC = 0x27138373;
struct malloc_info { struct malloc_info {
std::int32_t magic; std::int32_t magic;
std::int32_t size; std::int32_t size;
@ -139,9 +139,9 @@ struct HashtableNode {
std::atomic<std::size_t> size; std::atomic<std::size_t> size;
}; };
static constexpr std::size_t ht_max_size = 1000000; static constexpr std::size_t HT_MAX_SIZE = 1000000;
static std::atomic<std::size_t> ht_size{0}; static std::atomic<std::size_t> ht_size{0};
static std::array<HashtableNode, ht_max_size> ht; static std::array<HashtableNode, HT_MAX_SIZE> ht;
std::size_t get_ht_size() { std::size_t get_ht_size() {
return ht_size.load(); return ht_size.load();
@ -154,9 +154,9 @@ std::int32_t get_ht_pos(const Backtrace &bt, bool force = false) {
while (true) { while (true) {
auto pos_hash = ht[pos].hash.load(); auto pos_hash = ht[pos].hash.load();
if (pos_hash == 0) { if (pos_hash == 0) {
if (ht_size > ht_max_size / 2) { if (ht_size > HT_MAX_SIZE / 2) {
if (force) { if (force) {
assert(ht_size * 10 < ht_max_size * 7); assert(ht_size * 10 < HT_MAX_SIZE * 7);
} else { } else {
Backtrace unknown_bt{{nullptr}}; Backtrace unknown_bt{{nullptr}};
unknown_bt[0] = reinterpret_cast<void *>(1); unknown_bt[0] = reinterpret_cast<void *>(1);
@ -206,8 +206,8 @@ void register_xalloc(malloc_info *info, std::int32_t diff) {
extern "C" { extern "C" {
static void *malloc_with_frame(std::size_t size, const Backtrace &frame) { 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_SIZE % alignof(std::max_align_t) == 0, "fail");
static_assert(reserved >= sizeof(malloc_info), "fail"); static_assert(RESERVED_SIZE >= sizeof(malloc_info), "fail");
#if TD_DARWIN #if TD_DARWIN
static void *malloc_void = dlsym(RTLD_NEXT, "malloc"); static void *malloc_void = dlsym(RTLD_NEXT, "malloc");
static auto malloc_old = *reinterpret_cast<decltype(malloc) **>(&malloc_void); static auto malloc_old = *reinterpret_cast<decltype(malloc) **>(&malloc_void);
@ -215,26 +215,26 @@ static void *malloc_with_frame(std::size_t size, const Backtrace &frame) {
extern decltype(malloc) __libc_malloc; extern decltype(malloc) __libc_malloc;
static auto malloc_old = __libc_malloc; static auto malloc_old = __libc_malloc;
#endif #endif
auto *info = static_cast<malloc_info *>(malloc_old(size + reserved)); auto *info = static_cast<malloc_info *>(malloc_old(size + RESERVED_SIZE));
auto *buf = reinterpret_cast<char *>(info); auto *buf = reinterpret_cast<char *>(info);
info->magic = malloc_info_magic; info->magic = MALLOC_INFO_MAGIC;
info->size = static_cast<std::int32_t>(size); info->size = static_cast<std::int32_t>(size);
info->ht_pos = get_ht_pos(frame); info->ht_pos = get_ht_pos(frame);
register_xalloc(info, +1); register_xalloc(info, +1);
void *data = buf + reserved; void *data = buf + RESERVED_SIZE;
return data; return data;
} }
static malloc_info *get_info(void *data_void) { static malloc_info *get_info(void *data_void) {
char *data = static_cast<char *>(data_void); char *data = static_cast<char *>(data_void);
auto *buf = data - reserved; auto *buf = data - RESERVED_SIZE;
auto *info = reinterpret_cast<malloc_info *>(buf); auto *info = reinterpret_cast<malloc_info *>(buf);
assert(info->magic == malloc_info_magic); assert(info->magic == MALLOC_INFO_MAGIC);
return info; return info;
} }

View File

@ -63,7 +63,7 @@ class RequestActor : public Actor {
void raw_event(const Event::Raw &event) override { void raw_event(const Event::Raw &event) override {
if (future_.is_error()) { if (future_.is_error()) {
auto error = future_.move_as_error(); auto error = future_.move_as_error();
if (error == Status::Error<FutureActor<T>::Hangup>()) { if (error == Status::Error<FutureActor<T>::HANGUP_ERROR_CODE>()) {
// dropping query due to lost authorization or lost promise // dropping query due to lost authorization or lost promise
// td may be already closed, so we should check is auth_manager_ is empty // 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(); bool is_authorized = td->auth_manager_ && td->auth_manager_->is_authorized();

View File

@ -65,7 +65,7 @@ class SecretChatLogEventBase : public SecretChatEvent {
// inputEncryptedFile#5a17b5e5 id:long access_hash:long = InputEncryptedFile; // inputEncryptedFile#5a17b5e5 id:long access_hash:long = InputEncryptedFile;
// inputEncryptedFileBigUploaded#2dc173c8 id:long parts:int key_fingerprint:int = InputEncryptedFile; // inputEncryptedFileBigUploaded#2dc173c8 id:long parts:int key_fingerprint:int = InputEncryptedFile;
struct EncryptedInputFile { 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; enum Type : int32 { Empty = 0, Uploaded = 1, BigUploaded = 2, Location = 3 } type = Type::Empty;
int64 id = 0; int64 id = 0;
int64 access_hash = 0; int64 access_hash = 0;
@ -75,7 +75,7 @@ struct EncryptedInputFile {
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const { void store(StorerT &storer) const {
using td::store; using td::store;
store(magic, storer); store(MAGIC, storer);
store(type, storer); store(type, storer);
store(id, storer); store(id, storer);
store(access_hash, storer); store(access_hash, storer);
@ -104,7 +104,7 @@ struct EncryptedInputFile {
parse(parts, parser); parse(parts, parser);
parse(key_fingerprint, parser); parse(key_fingerprint, parser);
if (got_magic != magic) { if (got_magic != MAGIC) {
parser.set_error("EncryptedInputFile magic mismatch"); parser.set_error("EncryptedInputFile magic mismatch");
return; 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; // encryptedFile#4a70994c id:long access_hash:long size:int dc_id:int key_fingerprint:int = EncryptedFile;
struct EncryptedFileLocation { struct EncryptedFileLocation {
static constexpr int32 magic = 0x473d738a; static constexpr int32 MAGIC = 0x473d738a;
int64 id = 0; int64 id = 0;
int64 access_hash = 0; int64 access_hash = 0;
int32 size = 0; int32 size = 0;
@ -169,7 +169,7 @@ struct EncryptedFileLocation {
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const { void store(StorerT &storer) const {
using td::store; using td::store;
store(magic, storer); store(MAGIC, storer);
store(id, storer); store(id, storer);
store(access_hash, storer); store(access_hash, storer);
store(size, storer); store(size, storer);
@ -189,7 +189,7 @@ struct EncryptedFileLocation {
parse(dc_id, parser); parse(dc_id, parser);
parse(key_fingerprint, parser); parse(key_fingerprint, parser);
if (got_magic != magic) { if (got_magic != MAGIC) {
parser.set_error("EncryptedFileLocation magic mismatch"); parser.set_error("EncryptedFileLocation magic mismatch");
return; return;
} }

View File

@ -86,7 +86,7 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
if (id == 0) { if (id == 0) {
} else if (id == 1) { } else if (id == 1) {
total = stats; total = stats;
} else if (id == call_net_stats_id_) { } else if (id == CALL_NET_STATS_ID) {
} else if (file_type != FileType::None) { } else if (file_type != FileType::None) {
total_files = total_files + stats; total_files = total_files + stats;
} }
@ -109,7 +109,7 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
entry.duration = stats.duration; entry.duration = stats.duration;
if (id == 0) { if (id == 0) {
result.entries.push_back(std::move(entry)); 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; entry.is_call = true;
result.entries.push_back(std::move(entry)); result.entries.push_back(std::move(entry));
} else if (file_type != FileType::None) { } else if (file_type != FileType::None) {

View File

@ -119,7 +119,7 @@ class NetStatsManager : public Actor {
NetStatsInfo media_net_stats_; NetStatsInfo media_net_stats_;
std::array<NetStatsInfo, file_type_size> files_stats_; std::array<NetStatsInfo, file_type_size> files_stats_;
NetStatsInfo call_net_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 <class F> template <class F>
void for_each_stat(F &&f) { void for_each_stat(F &&f) {
@ -130,7 +130,7 @@ class NetStatsManager : public Actor {
auto file_type = static_cast<FileType>(file_type_i); auto file_type = static_cast<FileType>(file_type_i);
f(stat, file_type_i + 2, get_file_type_name(file_type), file_type); 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); void add_network_stats_impl(NetStatsInfo &info, const NetworkStatsEntry &entry);

View File

@ -408,7 +408,7 @@ class FutureActor final : public Actor {
public: public:
enum State { Waiting, Ready }; enum State { Waiting, Ready };
static constexpr int Hangup = 426487; static constexpr int HANGUP_ERROR_CODE = 426487;
FutureActor() = default; FutureActor() = default;
@ -487,7 +487,7 @@ class FutureActor final : public Actor {
} }
void hangup() override { void hangup() override {
set_error(Status::Error<Hangup>()); set_error(Status::Error<HANGUP_ERROR_CODE>());
} }
void start_up() override { void start_up() override {

View File

@ -34,7 +34,7 @@ namespace td {
template <class BinlogT> template <class BinlogT>
class BinlogKeyValue : public KeyValueSyncInterface { class BinlogKeyValue : public KeyValueSyncInterface {
public: public:
static constexpr int32 magic = 0x2a280000; static constexpr int32 MAGIC = 0x2a280000;
struct Event : public Storer { struct Event : public Storer {
Event() = default; Event() = default;
@ -236,7 +236,7 @@ class BinlogKeyValue : public KeyValueSyncInterface {
std::unordered_map<string, std::pair<string, uint64>> map_; std::unordered_map<string, std::pair<string, uint64>> map_;
std::shared_ptr<BinlogT> binlog_; std::shared_ptr<BinlogT> binlog_;
RwMutex rw_mutex_; RwMutex rw_mutex_;
int32 magic_ = magic; int32 magic_ = MAGIC;
}; };
template <> template <>

View File

@ -22,14 +22,14 @@ namespace td {
StringBuilder::StringBuilder(MutableSlice slice, bool use_buffer) StringBuilder::StringBuilder(MutableSlice slice, bool use_buffer)
: begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) { : begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) {
if (slice.size() <= reserved_size) { if (slice.size() <= RESERVED_SIZE) {
auto buffer_size = reserved_size + 100; auto buffer_size = RESERVED_SIZE + 100;
buffer_ = std::make_unique<char[]>(buffer_size); buffer_ = std::make_unique<char[]>(buffer_size);
begin_ptr_ = buffer_.get(); begin_ptr_ = buffer_.get();
current_ptr_ = begin_ptr_; current_ptr_ = begin_ptr_;
end_ptr_ = begin_ptr_ + buffer_size - reserved_size; end_ptr_ = begin_ptr_ + buffer_size - RESERVED_SIZE;
} else { } 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_) { if (end_ptr_ < current_ptr_) {
return on_error(); return on_error();
} }
auto available_size = static_cast<size_t>(end_ptr_ + reserved_size - 1 - current_ptr_); auto available_size = static_cast<size_t>(end_ptr_ + RESERVED_SIZE - 1 - current_ptr_);
if (size > available_size) { if (size > available_size) {
error_flag_ = true; error_flag_ = true;
size = available_size; size = available_size;
@ -101,12 +101,12 @@ bool StringBuilder::reserve_inner(size_t size) {
} }
size_t old_data_size = current_ptr_ - begin_ptr_; size_t old_data_size = current_ptr_ - begin_ptr_;
if (size >= std::numeric_limits<size_t>::max() - reserved_size - old_data_size - 1) { if (size >= std::numeric_limits<size_t>::max() - RESERVED_SIZE - old_data_size - 1) {
return false; return false;
} }
size_t need_data_size = old_data_size + size; size_t need_data_size = old_data_size + size;
size_t old_buffer_size = end_ptr_ - begin_ptr_; size_t old_buffer_size = end_ptr_ - begin_ptr_;
if (old_buffer_size >= (std::numeric_limits<size_t>::max() - reserved_size) / 2 - 2) { if (old_buffer_size >= (std::numeric_limits<size_t>::max() - RESERVED_SIZE) / 2 - 2) {
return false; return false;
} }
size_t new_buffer_size = (old_buffer_size + 1) * 2; 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) { if (new_buffer_size < 100) {
new_buffer_size = 100; new_buffer_size = 100;
} }
new_buffer_size += reserved_size; new_buffer_size += RESERVED_SIZE;
auto new_buffer = std::make_unique<char[]>(new_buffer_size); auto new_buffer = std::make_unique<char[]>(new_buffer_size);
std::memcpy(new_buffer.get(), begin_ptr_, old_data_size); std::memcpy(new_buffer.get(), begin_ptr_, old_data_size);
buffer_ = std::move(new_buffer); buffer_ = std::move(new_buffer);
begin_ptr_ = buffer_.get(); begin_ptr_ = buffer_.get();
current_ptr_ = begin_ptr_ + old_data_size; 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(end_ptr_ > current_ptr_);
CHECK(static_cast<size_t>(end_ptr_ - current_ptr_) >= size); CHECK(static_cast<size_t>(end_ptr_ - current_ptr_) >= size);
return true; return true;
@ -193,7 +193,7 @@ StringBuilder &StringBuilder::operator<<(FixedDouble x) {
*ss << x.d; *ss << x.d;
int len = narrow_cast<int>(static_cast<std::streamoff>(ss->tellp())); int len = narrow_cast<int>(static_cast<std::streamoff>(ss->tellp()));
auto left = end_ptr_ + reserved_size - current_ptr_; auto left = end_ptr_ + RESERVED_SIZE - current_ptr_;
if (unlikely(len >= left)) { if (unlikely(len >= left)) {
error_flag_ = true; error_flag_ = true;
len = left ? narrow_cast<int>(left - 1) : 0; len = left ? narrow_cast<int>(left - 1) : 0;
@ -207,7 +207,7 @@ StringBuilder &StringBuilder::operator<<(const void *ptr) {
if (unlikely(!reserve())) { if (unlikely(!reserve())) {
return on_error(); 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; return *this;
} }

View File

@ -26,7 +26,7 @@ class StringBuilder {
} }
MutableCSlice as_cslice() { MutableCSlice as_cslice() {
if (current_ptr_ >= end_ptr_ + reserved_size) { if (current_ptr_ >= end_ptr_ + RESERVED_SIZE) {
std::abort(); // shouldn't happen std::abort(); // shouldn't happen
} }
*current_ptr_ = 0; *current_ptr_ = 0;
@ -104,7 +104,7 @@ class StringBuilder {
bool error_flag_ = false; bool error_flag_ = false;
bool use_buffer_ = false; bool use_buffer_ = false;
std::unique_ptr<char[]> buffer_; std::unique_ptr<char[]> buffer_;
static constexpr size_t reserved_size = 30; static constexpr size_t RESERVED_SIZE = 30;
StringBuilder &on_error() { StringBuilder &on_error() {
error_flag_ = true; error_flag_ = true;
@ -115,7 +115,7 @@ class StringBuilder {
if (end_ptr_ > current_ptr_) { if (end_ptr_ > current_ptr_) {
return true; return true;
} }
return reserve_inner(reserved_size); return reserve_inner(RESERVED_SIZE);
} }
bool reserve(size_t size) { bool reserve(size_t size) {
if (end_ptr_ > current_ptr_ && static_cast<size_t>(end_ptr_ - current_ptr_) >= size) { if (end_ptr_ > current_ptr_ && static_cast<size_t>(end_ptr_ - current_ptr_) >= size) {

View File

@ -814,11 +814,11 @@ static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max) {
} }
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) { Result<uint32> 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<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max) { Result<uint32> 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 #else
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) { Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) {

View File

@ -84,8 +84,8 @@ class UdpSocketFd {
#endif #endif
private: private:
static constexpr uint32 default_udp_max_snd_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); static constexpr uint32 DEFAULT_UDP_MAX_RCV_BUFFER_SIZE = (1 << 24);
std::unique_ptr<detail::UdpSocketFdImpl, detail::UdpSocketFdImplDeleter> impl_; std::unique_ptr<detail::UdpSocketFdImpl, detail::UdpSocketFdImplDeleter> impl_;
explicit UdpSocketFd(unique_ptr<detail::UdpSocketFdImpl> impl); explicit UdpSocketFd(unique_ptr<detail::UdpSocketFdImpl> impl);
}; };

View File

@ -187,7 +187,7 @@ class HashMapBenchmark : public td::Benchmark {
size_t threads_n = 16; size_t threads_n = 16;
int mod_; int mod_;
static constexpr size_t mul_ = 7273; //1000000000 + 7; static constexpr size_t MUL = 7273; //1000000000 + 7;
int n_; int n_;
public: public:
@ -211,7 +211,7 @@ class HashMapBenchmark : public td::Benchmark {
size_t r = n * (i + 1) / threads_n; size_t r = n * (i + 1) / threads_n;
threads.emplace_back([l, r, this] { threads.emplace_back([l, r, this] {
for (size_t i = l; i < r; i++) { for (size_t i = l; i < r; i++) {
auto x = td::narrow_cast<int>((i + 1) * mul_ % n_) + 3; auto x = td::narrow_cast<int>((i + 1) * MUL % n_) + 3;
auto y = td::narrow_cast<int>(i + 2); auto y = td::narrow_cast<int>(i + 2);
hash_map->insert(x, y); hash_map->insert(x, y);
} }
@ -224,7 +224,7 @@ class HashMapBenchmark : public td::Benchmark {
void tear_down() override { void tear_down() override {
for (int i = 0; i < n_; i++) { for (int i = 0; i < n_; i++) {
auto x = td::narrow_cast<int>((i + 1) * mul_ % n_) + 3; auto x = td::narrow_cast<int>((i + 1) * MUL % n_) + 3;
auto y = td::narrow_cast<int>(i + 2); auto y = td::narrow_cast<int>(i + 2);
ASSERT_EQ(y, hash_map->find(x, -1)); ASSERT_EQ(y, hash_map->find(x, -1));
} }