Skip to content

Commit 3442a88

Browse files
committed
Unify constant names style.
GitOrigin-RevId: 6e4475366b94cea6ab0331d57f254311490bdee2
1 parent 40ee207 commit 3442a88

File tree

12 files changed

+49
-49
lines changed

12 files changed

+49
-49
lines changed

‎memprof/memprof.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ static Backtrace get_backtrace() {
117117
return res;
118118
}
119119

120-
static constexpr std::size_t reserved = 16;
121-
static constexpr std::int32_t malloc_info_magic = 0x27138373;
120+
static constexpr std::size_t RESERVED_SIZE = 16;
121+
static constexpr std::int32_t MALLOC_INFO_MAGIC = 0x27138373;
122122
struct malloc_info {
123123
std::int32_t magic;
124124
std::int32_t size;
@@ -139,9 +139,9 @@ struct HashtableNode {
139139
std::atomic<std::size_t> size;
140140
};
141141

142-
static constexpr std::size_t ht_max_size = 1000000;
142+
static constexpr std::size_t HT_MAX_SIZE = 1000000;
143143
static std::atomic<std::size_t> ht_size{0};
144-
static std::array<HashtableNode, ht_max_size> ht;
144+
static std::array<HashtableNode, HT_MAX_SIZE> ht;
145145

146146
std::size_t get_ht_size() {
147147
return ht_size.load();
@@ -154,9 +154,9 @@ std::int32_t get_ht_pos(const Backtrace &bt, bool force = false) {
154154
while (true) {
155155
auto pos_hash = ht[pos].hash.load();
156156
if (pos_hash == 0) {
157-
if (ht_size > ht_max_size / 2) {
157+
if (ht_size > HT_MAX_SIZE / 2) {
158158
if (force) {
159-
assert(ht_size * 10 < ht_max_size * 7);
159+
assert(ht_size * 10 < HT_MAX_SIZE * 7);
160160
} else {
161161
Backtrace unknown_bt{{nullptr}};
162162
unknown_bt[0] = reinterpret_cast<void *>(1);
@@ -206,35 +206,35 @@ void register_xalloc(malloc_info *info, std::int32_t diff) {
206206
extern "C" {
207207

208208
static void *malloc_with_frame(std::size_t size, const Backtrace &frame) {
209-
static_assert(reserved % alignof(std::max_align_t) == 0, "fail");
210-
static_assert(reserved >= sizeof(malloc_info), "fail");
209+
static_assert(RESERVED_SIZE % alignof(std::max_align_t) == 0, "fail");
210+
static_assert(RESERVED_SIZE >= sizeof(malloc_info), "fail");
211211
#if TD_DARWIN
212212
static void *malloc_void = dlsym(RTLD_NEXT, "malloc");
213213
static auto malloc_old = *reinterpret_cast<decltype(malloc) **>(&malloc_void);
214214
#else
215215
extern decltype(malloc) __libc_malloc;
216216
static auto malloc_old = __libc_malloc;
217217
#endif
218-
auto *info = static_cast<malloc_info *>(malloc_old(size + reserved));
218+
auto *info = static_cast<malloc_info *>(malloc_old(size + RESERVED_SIZE));
219219
auto *buf = reinterpret_cast<char *>(info);
220220

221-
info->magic = malloc_info_magic;
221+
info->magic = MALLOC_INFO_MAGIC;
222222
info->size = static_cast<std::int32_t>(size);
223223
info->ht_pos = get_ht_pos(frame);
224224

225225
register_xalloc(info, +1);
226226

227-
void *data = buf + reserved;
227+
void *data = buf + RESERVED_SIZE;
228228

229229
return data;
230230
}
231231

232232
static malloc_info *get_info(void *data_void) {
233233
char *data = static_cast<char *>(data_void);
234-
auto *buf = data - reserved;
234+
auto *buf = data - RESERVED_SIZE;
235235

236236
auto *info = reinterpret_cast<malloc_info *>(buf);
237-
assert(info->magic == malloc_info_magic);
237+
assert(info->magic == MALLOC_INFO_MAGIC);
238238
return info;
239239
}
240240

‎td/telegram/RequestActor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RequestActor : public Actor {
6363
void raw_event(const Event::Raw &event) override {
6464
if (future_.is_error()) {
6565
auto error = future_.move_as_error();
66-
if (error == Status::Error<FutureActor<T>::Hangup>()) {
66+
if (error == Status::Error<FutureActor<T>::HANGUP_ERROR_CODE>()) {
6767
// dropping query due to lost authorization or lost promise
6868
// td may be already closed, so we should check is auth_manager_ is empty
6969
bool is_authorized = td->auth_manager_ && td->auth_manager_->is_authorized();

‎td/telegram/logevent/SecretChatEvent.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SecretChatLogEventBase : public SecretChatEvent {
6565
// inputEncryptedFile#5a17b5e5 id:long access_hash:long = InputEncryptedFile;
6666
// inputEncryptedFileBigUploaded#2dc173c8 id:long parts:int key_fingerprint:int = InputEncryptedFile;
6767
struct EncryptedInputFile {
68-
static constexpr int32 magic = 0x4328d38a;
68+
static constexpr int32 MAGIC = 0x4328d38a;
6969
enum Type : int32 { Empty = 0, Uploaded = 1, BigUploaded = 2, Location = 3 } type = Type::Empty;
7070
int64 id = 0;
7171
int64 access_hash = 0;
@@ -75,7 +75,7 @@ struct EncryptedInputFile {
7575
template <class StorerT>
7676
void store(StorerT &storer) const {
7777
using td::store;
78-
store(magic, storer);
78+
store(MAGIC, storer);
7979
store(type, storer);
8080
store(id, storer);
8181
store(access_hash, storer);
@@ -104,7 +104,7 @@ struct EncryptedInputFile {
104104
parse(parts, parser);
105105
parse(key_fingerprint, parser);
106106

107-
if (got_magic != magic) {
107+
if (got_magic != MAGIC) {
108108
parser.set_error("EncryptedInputFile magic mismatch");
109109
return;
110110
}
@@ -156,7 +156,7 @@ inline StringBuilder &operator<<(StringBuilder &sb, const EncryptedInputFile &fi
156156

157157
// encryptedFile#4a70994c id:long access_hash:long size:int dc_id:int key_fingerprint:int = EncryptedFile;
158158
struct EncryptedFileLocation {
159-
static constexpr int32 magic = 0x473d738a;
159+
static constexpr int32 MAGIC = 0x473d738a;
160160
int64 id = 0;
161161
int64 access_hash = 0;
162162
int32 size = 0;
@@ -169,7 +169,7 @@ struct EncryptedFileLocation {
169169
template <class StorerT>
170170
void store(StorerT &storer) const {
171171
using td::store;
172-
store(magic, storer);
172+
store(MAGIC, storer);
173173
store(id, storer);
174174
store(access_hash, storer);
175175
store(size, storer);
@@ -189,7 +189,7 @@ struct EncryptedFileLocation {
189189
parse(dc_id, parser);
190190
parse(key_fingerprint, parser);
191191

192-
if (got_magic != magic) {
192+
if (got_magic != MAGIC) {
193193
parser.set_error("EncryptedFileLocation magic mismatch");
194194
return;
195195
}

‎td/telegram/net/NetStatsManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
8686
if (id == 0) {
8787
} else if (id == 1) {
8888
total = stats;
89-
} else if (id == call_net_stats_id_) {
89+
} else if (id == CALL_NET_STATS_ID) {
9090
} else if (file_type != FileType::None) {
9191
total_files = total_files + stats;
9292
}
@@ -109,7 +109,7 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
109109
entry.duration = stats.duration;
110110
if (id == 0) {
111111
result.entries.push_back(std::move(entry));
112-
} else if (id == call_net_stats_id_) {
112+
} else if (id == CALL_NET_STATS_ID) {
113113
entry.is_call = true;
114114
result.entries.push_back(std::move(entry));
115115
} else if (file_type != FileType::None) {

‎td/telegram/net/NetStatsManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class NetStatsManager : public Actor {
119119
NetStatsInfo media_net_stats_;
120120
std::array<NetStatsInfo, file_type_size> files_stats_;
121121
NetStatsInfo call_net_stats_;
122-
static constexpr int32 call_net_stats_id_{file_type_size + 2};
122+
static constexpr int32 CALL_NET_STATS_ID{file_type_size + 2};
123123

124124
template <class F>
125125
void for_each_stat(F &&f) {
@@ -130,7 +130,7 @@ class NetStatsManager : public Actor {
130130
auto file_type = static_cast<FileType>(file_type_i);
131131
f(stat, file_type_i + 2, get_file_type_name(file_type), file_type);
132132
}
133-
f(call_net_stats_, call_net_stats_id_, CSlice("calls"), FileType::None);
133+
f(call_net_stats_, CALL_NET_STATS_ID, CSlice("calls"), FileType::None);
134134
}
135135

136136
void add_network_stats_impl(NetStatsInfo &info, const NetworkStatsEntry &entry);

‎tdactor/td/actor/PromiseFuture.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class FutureActor final : public Actor {
408408
public:
409409
enum State { Waiting, Ready };
410410

411-
static constexpr int Hangup = 426487;
411+
static constexpr int HANGUP_ERROR_CODE = 426487;
412412

413413
FutureActor() = default;
414414

@@ -487,7 +487,7 @@ class FutureActor final : public Actor {
487487
}
488488

489489
void hangup() override {
490-
set_error(Status::Error<Hangup>());
490+
set_error(Status::Error<HANGUP_ERROR_CODE>());
491491
}
492492

493493
void start_up() override {

‎tddb/td/db/BinlogKeyValue.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace td {
3434
template <class BinlogT>
3535
class BinlogKeyValue : public KeyValueSyncInterface {
3636
public:
37-
static constexpr int32 magic = 0x2a280000;
37+
static constexpr int32 MAGIC = 0x2a280000;
3838

3939
struct Event : public Storer {
4040
Event() = default;
@@ -236,7 +236,7 @@ class BinlogKeyValue : public KeyValueSyncInterface {
236236
std::unordered_map<string, std::pair<string, uint64>> map_;
237237
std::shared_ptr<BinlogT> binlog_;
238238
RwMutex rw_mutex_;
239-
int32 magic_ = magic;
239+
int32 magic_ = MAGIC;
240240
};
241241

242242
template <>

‎tdutils/td/utils/StringBuilder.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ namespace td {
2222

2323
StringBuilder::StringBuilder(MutableSlice slice, bool use_buffer)
2424
: begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) {
25-
if (slice.size() <= reserved_size) {
26-
auto buffer_size = reserved_size + 100;
25+
if (slice.size() <= RESERVED_SIZE) {
26+
auto buffer_size = RESERVED_SIZE + 100;
2727
buffer_ = std::make_unique<char[]>(buffer_size);
2828
begin_ptr_ = buffer_.get();
2929
current_ptr_ = begin_ptr_;
30-
end_ptr_ = begin_ptr_ + buffer_size - reserved_size;
30+
end_ptr_ = begin_ptr_ + buffer_size - RESERVED_SIZE;
3131
} else {
32-
end_ptr_ = slice.end() - reserved_size;
32+
end_ptr_ = slice.end() - RESERVED_SIZE;
3333
}
3434
}
3535

@@ -39,7 +39,7 @@ StringBuilder &StringBuilder::operator<<(Slice slice) {
3939
if (end_ptr_ < current_ptr_) {
4040
return on_error();
4141
}
42-
auto available_size = static_cast<size_t>(end_ptr_ + reserved_size - 1 - current_ptr_);
42+
auto available_size = static_cast<size_t>(end_ptr_ + RESERVED_SIZE - 1 - current_ptr_);
4343
if (size > available_size) {
4444
error_flag_ = true;
4545
size = available_size;
@@ -101,12 +101,12 @@ bool StringBuilder::reserve_inner(size_t size) {
101101
}
102102

103103
size_t old_data_size = current_ptr_ - begin_ptr_;
104-
if (size >= std::numeric_limits<size_t>::max() - reserved_size - old_data_size - 1) {
104+
if (size >= std::numeric_limits<size_t>::max() - RESERVED_SIZE - old_data_size - 1) {
105105
return false;
106106
}
107107
size_t need_data_size = old_data_size + size;
108108
size_t old_buffer_size = end_ptr_ - begin_ptr_;
109-
if (old_buffer_size >= (std::numeric_limits<size_t>::max() - reserved_size) / 2 - 2) {
109+
if (old_buffer_size >= (std::numeric_limits<size_t>::max() - RESERVED_SIZE) / 2 - 2) {
110110
return false;
111111
}
112112
size_t new_buffer_size = (old_buffer_size + 1) * 2;
@@ -116,13 +116,13 @@ bool StringBuilder::reserve_inner(size_t size) {
116116
if (new_buffer_size < 100) {
117117
new_buffer_size = 100;
118118
}
119-
new_buffer_size += reserved_size;
119+
new_buffer_size += RESERVED_SIZE;
120120
auto new_buffer = std::make_unique<char[]>(new_buffer_size);
121121
std::memcpy(new_buffer.get(), begin_ptr_, old_data_size);
122122
buffer_ = std::move(new_buffer);
123123
begin_ptr_ = buffer_.get();
124124
current_ptr_ = begin_ptr_ + old_data_size;
125-
end_ptr_ = begin_ptr_ + new_buffer_size - reserved_size;
125+
end_ptr_ = begin_ptr_ + new_buffer_size - RESERVED_SIZE;
126126
CHECK(end_ptr_ > current_ptr_);
127127
CHECK(static_cast<size_t>(end_ptr_ - current_ptr_) >= size);
128128
return true;
@@ -193,7 +193,7 @@ StringBuilder &StringBuilder::operator<<(FixedDouble x) {
193193
*ss << x.d;
194194

195195
int len = narrow_cast<int>(static_cast<std::streamoff>(ss->tellp()));
196-
auto left = end_ptr_ + reserved_size - current_ptr_;
196+
auto left = end_ptr_ + RESERVED_SIZE - current_ptr_;
197197
if (unlikely(len >= left)) {
198198
error_flag_ = true;
199199
len = left ? narrow_cast<int>(left - 1) : 0;
@@ -207,7 +207,7 @@ StringBuilder &StringBuilder::operator<<(const void *ptr) {
207207
if (unlikely(!reserve())) {
208208
return on_error();
209209
}
210-
current_ptr_ += std::snprintf(current_ptr_, reserved_size, "%p", ptr);
210+
current_ptr_ += std::snprintf(current_ptr_, RESERVED_SIZE, "%p", ptr);
211211
return *this;
212212
}
213213

‎tdutils/td/utils/StringBuilder.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class StringBuilder {
2626
}
2727

2828
MutableCSlice as_cslice() {
29-
if (current_ptr_ >= end_ptr_ + reserved_size) {
29+
if (current_ptr_ >= end_ptr_ + RESERVED_SIZE) {
3030
std::abort(); // shouldn't happen
3131
}
3232
*current_ptr_ = 0;
@@ -104,7 +104,7 @@ class StringBuilder {
104104
bool error_flag_ = false;
105105
bool use_buffer_ = false;
106106
std::unique_ptr<char[]> buffer_;
107-
static constexpr size_t reserved_size = 30;
107+
static constexpr size_t RESERVED_SIZE = 30;
108108

109109
StringBuilder &on_error() {
110110
error_flag_ = true;
@@ -115,7 +115,7 @@ class StringBuilder {
115115
if (end_ptr_ > current_ptr_) {
116116
return true;
117117
}
118-
return reserve_inner(reserved_size);
118+
return reserve_inner(RESERVED_SIZE);
119119
}
120120
bool reserve(size_t size) {
121121
if (end_ptr_ > current_ptr_ && static_cast<size_t>(end_ptr_ - current_ptr_) >= size) {

‎tdutils/td/utils/port/UdpSocketFd.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,11 @@ static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max) {
814814
}
815815

816816
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) {
817-
return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max == 0 ? default_udp_max_snd_buffer_size : max);
817+
return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max == 0 ? DEFAULT_UDP_MAX_SND_BUFFER_SIZE : max);
818818
}
819819

820820
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max) {
821-
return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max == 0 ? default_udp_max_rcv_buffer_size : max);
821+
return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max == 0 ? DEFAULT_UDP_MAX_RCV_BUFFER_SIZE : max);
822822
}
823823
#else
824824
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) {

‎tdutils/td/utils/port/UdpSocketFd.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class UdpSocketFd {
8484
#endif
8585

8686
private:
87-
static constexpr uint32 default_udp_max_snd_buffer_size = (1 << 24);
88-
static constexpr uint32 default_udp_max_rcv_buffer_size = (1 << 24);
87+
static constexpr uint32 DEFAULT_UDP_MAX_SND_BUFFER_SIZE = (1 << 24);
88+
static constexpr uint32 DEFAULT_UDP_MAX_RCV_BUFFER_SIZE = (1 << 24);
8989
std::unique_ptr<detail::UdpSocketFdImpl, detail::UdpSocketFdImplDeleter> impl_;
9090
explicit UdpSocketFd(unique_ptr<detail::UdpSocketFdImpl> impl);
9191
};

‎tdutils/test/ConcurrentHashMap.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class HashMapBenchmark : public td::Benchmark {
187187

188188
size_t threads_n = 16;
189189
int mod_;
190-
static constexpr size_t mul_ = 7273; //1000000000 + 7;
190+
static constexpr size_t MUL = 7273; //1000000000 + 7;
191191
int n_;
192192

193193
public:
@@ -211,7 +211,7 @@ class HashMapBenchmark : public td::Benchmark {
211211
size_t r = n * (i + 1) / threads_n;
212212
threads.emplace_back([l, r, this] {
213213
for (size_t i = l; i < r; i++) {
214-
auto x = td::narrow_cast<int>((i + 1) * mul_ % n_) + 3;
214+
auto x = td::narrow_cast<int>((i + 1) * MUL % n_) + 3;
215215
auto y = td::narrow_cast<int>(i + 2);
216216
hash_map->insert(x, y);
217217
}
@@ -224,7 +224,7 @@ class HashMapBenchmark : public td::Benchmark {
224224

225225
void tear_down() override {
226226
for (int i = 0; i < n_; i++) {
227-
auto x = td::narrow_cast<int>((i + 1) * mul_ % n_) + 3;
227+
auto x = td::narrow_cast<int>((i + 1) * MUL % n_) + 3;
228228
auto y = td::narrow_cast<int>(i + 2);
229229
ASSERT_EQ(y, hash_map->find(x, -1));
230230
}

0 commit comments

Comments
 (0)