diff --git a/benchmark/bench_queue.cpp b/benchmark/bench_queue.cpp index af5f48c32..75241894a 100644 --- a/benchmark/bench_queue.cpp +++ b/benchmark/bench_queue.cpp @@ -903,12 +903,12 @@ class RingBenchmark : public td::Benchmark { void test_queue() { std::vector threads; - constexpr size_t threads_n = 100; - std::vector> queues(threads_n); + static constexpr size_t THREAD_COUNT = 100; + std::vector> queues(THREAD_COUNT); for (auto &q : queues) { q.init(); } - for (size_t i = 0; i < threads_n; i++) { + for (size_t i = 0; i < THREAD_COUNT; i++) { threads.emplace_back([&q = queues[i]] { while (true) { auto got = q.reader_wait_nonblock(); @@ -923,7 +923,7 @@ void test_queue() { while (true) { td::usleep_for(100); for (int i = 0; i < 5; i++) { - queues[td::Random::fast(0, threads_n - 1)].writer_put(1); + queues[td::Random::fast(0, THREAD_COUNT - 1)].writer_put(1); } } } diff --git a/tdutils/td/utils/BufferedFd.h b/tdutils/td/utils/BufferedFd.h index 05c826631..b2841e996 100644 --- a/tdutils/td/utils/BufferedFd.h +++ b/tdutils/td/utils/BufferedFd.h @@ -109,12 +109,12 @@ Result BufferedFdBase::flush_write() { write_->sync_with_writer(); size_t result = 0; while (!write_->empty() && ::td::can_write(*this)) { - constexpr size_t buf_size = 20; - IoSlice buf[buf_size]; + constexpr size_t BUF_SIZE = 20; + IoSlice buf[BUF_SIZE]; auto it = write_->clone(); size_t buf_i; - for (buf_i = 0; buf_i < buf_size; buf_i++) { + for (buf_i = 0; buf_i < BUF_SIZE; buf_i++) { Slice slice = it.prepare_read(); if (slice.empty()) { break; diff --git a/tdutils/td/utils/MemoryLog.h b/tdutils/td/utils/MemoryLog.h index 94b60850f..108e62c0d 100644 --- a/tdutils/td/utils/MemoryLog.h +++ b/tdutils/td/utils/MemoryLog.h @@ -34,30 +34,30 @@ class MemoryLog : public LogInterface { size_t slice_size = slice.size(); CHECK(slice_size * 3 < buffer_size); size_t pad_size = ((slice_size + 15) & ~15) - slice_size; - constexpr size_t magic_size = 16; - uint32 total_size = static_cast(slice_size + pad_size + magic_size); + constexpr size_t MAGIC_SIZE = 16; + uint32 total_size = static_cast(slice_size + pad_size + MAGIC_SIZE); uint32 real_pos = pos_.fetch_add(total_size, std::memory_order_relaxed); CHECK((total_size & 15) == 0); uint32 start_pos = real_pos & (buffer_size - 1); uint32 end_pos = start_pos + total_size; if (likely(end_pos <= buffer_size)) { - std::memcpy(&buffer_[start_pos + magic_size], slice.data(), slice_size); - std::memcpy(&buffer_[start_pos + magic_size + slice_size], " ", pad_size); + std::memcpy(&buffer_[start_pos + MAGIC_SIZE], slice.data(), slice_size); + std::memcpy(&buffer_[start_pos + MAGIC_SIZE + slice_size], " ", pad_size); } else { - size_t first = buffer_size - start_pos - magic_size; + size_t first = buffer_size - start_pos - MAGIC_SIZE; size_t second = slice_size - first; - std::memcpy(&buffer_[start_pos + magic_size], slice.data(), first); + std::memcpy(&buffer_[start_pos + MAGIC_SIZE], slice.data(), first); std::memcpy(&buffer_[0], slice.data() + first, second); std::memcpy(&buffer_[second], " ", pad_size); } CHECK((start_pos & 15) == 0); - CHECK(start_pos <= buffer_size - magic_size); + CHECK(start_pos <= buffer_size - MAGIC_SIZE); buffer_[start_pos] = '\n'; - size_t printed = std::snprintf(&buffer_[start_pos + 1], magic_size - 1, "LOG:%08x: ", real_pos); - CHECK(printed == magic_size - 2); - buffer_[start_pos + magic_size - 1] = ' '; + size_t printed = std::snprintf(&buffer_[start_pos + 1], MAGIC_SIZE - 1, "LOG:%08x: ", real_pos); + CHECK(printed == MAGIC_SIZE - 2); + buffer_[start_pos + MAGIC_SIZE - 1] = ' '; if (log_level == VERBOSITY_NAME(FATAL)) { process_fatal_error(new_slice); diff --git a/tdutils/td/utils/Random.cpp b/tdutils/td/utils/Random.cpp index ea49162b2..73e1990ec 100644 --- a/tdutils/td/utils/Random.cpp +++ b/tdutils/td/utils/Random.cpp @@ -31,20 +31,20 @@ void Random::secure_bytes(MutableSlice dest) { } void Random::secure_bytes(unsigned char *ptr, size_t size) { - constexpr size_t buf_size = 512; + constexpr size_t BUF_SIZE = 512; static TD_THREAD_LOCAL unsigned char *buf; // static zero-initialized static TD_THREAD_LOCAL size_t buf_pos; static TD_THREAD_LOCAL int64 generation; - if (init_thread_local(buf, buf_size)) { - buf_pos = buf_size; + if (init_thread_local(buf, BUF_SIZE)) { + buf_pos = BUF_SIZE; generation = 0; } if (generation != random_seed_generation.load(std::memory_order_relaxed)) { generation = random_seed_generation.load(std::memory_order_acquire); - buf_pos = buf_size; + buf_pos = BUF_SIZE; } - auto ready = 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; @@ -54,8 +54,8 @@ void Random::secure_bytes(unsigned char *ptr, size_t size) { return; } } - if (size < buf_size) { - int err = RAND_bytes(buf, static_cast(buf_size)); + if (size < BUF_SIZE) { + int err = RAND_bytes(buf, static_cast(BUF_SIZE)); // TODO: it CAN fail LOG_IF(FATAL, err != 1); buf_pos = size; diff --git a/tdutils/td/utils/port/SocketFd.cpp b/tdutils/td/utils/port/SocketFd.cpp index 3fa3a1f85..c669a586f 100644 --- a/tdutils/td/utils/port/SocketFd.cpp +++ b/tdutils/td/utils/port/SocketFd.cpp @@ -218,11 +218,11 @@ class SocketFdImpl : private Iocp::Callback { return; } std::memset(&write_overlapped_, 0, sizeof(write_overlapped_)); - constexpr size_t buf_size = 20; - WSABUF buf[buf_size]; + constexpr size_t BUF_SIZE = 20; + WSABUF buf[BUF_SIZE]; auto it = output_reader_.clone(); size_t buf_i; - for (buf_i = 0; buf_i < buf_size; buf_i++) { + for (buf_i = 0; buf_i < BUF_SIZE; buf_i++) { auto src = it.prepare_read(); if (src.empty()) { break; diff --git a/test/set_with_position.cpp b/test/set_with_position.cpp index 11e948872..f52425477 100644 --- a/test/set_with_position.cpp +++ b/test/set_with_position.cpp @@ -229,7 +229,7 @@ template