Remove enum usages for static constants creation.

GitOrigin-RevId: 2a88fd2cd961398a09403fe35a15ae56372a44f8
This commit is contained in:
levlam 2020-06-15 04:52:56 +03:00
parent ea4841a37c
commit 0cf4fea1ff
5 changed files with 17 additions and 13 deletions

View File

@ -40,8 +40,8 @@ class IostreamWriteBench : public td::Benchmark {
protected: protected:
std::string file_name_; std::string file_name_;
std::ofstream stream; std::ofstream stream;
enum { buffer_size = 1 << 20 }; static constexpr std::size_t BUFFER_SIZE = 1 << 20;
char buffer[buffer_size]; char buffer[BUFFER_SIZE];
public: public:
std::string get_description() const override { std::string get_description() const override {
@ -52,7 +52,7 @@ class IostreamWriteBench : public td::Benchmark {
file_name_ = create_tmp_file(); file_name_ = create_tmp_file();
stream.open(file_name_.c_str()); stream.open(file_name_.c_str());
CHECK(stream.is_open()); CHECK(stream.is_open());
// stream.rdbuf()->pubsetbuf(buffer, buffer_size); // stream.rdbuf()->pubsetbuf(buffer, BUFFER_SIZE);
} }
void run(int n) override { void run(int n) override {
@ -71,8 +71,8 @@ class FILEWriteBench : public td::Benchmark {
protected: protected:
std::string file_name_; std::string file_name_;
FILE *file; FILE *file;
enum { buffer_size = 1 << 20 }; static constexpr std::size_t BUFFER_SIZE = 1 << 20;
char buffer[buffer_size]; char buffer[BUFFER_SIZE];
public: public:
std::string get_description() const override { std::string get_description() const override {
@ -82,7 +82,7 @@ class FILEWriteBench : public td::Benchmark {
void start_up() override { void start_up() override {
file_name_ = create_tmp_file(); file_name_ = create_tmp_file();
file = fopen(file_name_.c_str(), "w"); file = fopen(file_name_.c_str(), "w");
// setvbuf(file, buffer, _IOFBF, buffer_size); // setvbuf(file, buffer, _IOFBF, BUFFER_SIZE);
} }
void run(int n) override { void run(int n) override {
@ -123,8 +123,8 @@ class LogWriteBench : public td::Benchmark {
std::string file_name_; std::string file_name_;
std::ofstream stream; std::ofstream stream;
std::streambuf *old_buf; std::streambuf *old_buf;
enum { buffer_size = 1 << 20 }; static constexpr std::size_t BUFFER_SIZE = 1 << 20;
char buffer[buffer_size]; char buffer[BUFFER_SIZE];
public: public:
std::string get_description() const override { std::string get_description() const override {

View File

@ -837,7 +837,7 @@ class QueueBenchmark : public td::Benchmark {
template <class QueueT> template <class QueueT>
class RingBenchmark : public td::Benchmark { class RingBenchmark : public td::Benchmark {
enum { QN = 504 }; static constexpr int QN = 504;
struct Thread { struct Thread {
int int_id; int int_id;

View File

@ -66,7 +66,9 @@ class AuthKey {
auth_key_.clear(); auth_key_.clear();
} }
enum : int32 { AUTH_FLAG = 1, WAS_AUTH_FLAG = 2, HAS_CREATED_AT = 4 }; static constexpr int32 AUTH_FLAG = 1;
static constexpr int32 WAS_AUTH_FLAG = 2;
static constexpr int32 HAS_CREATED_AT = 4;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const { void store(StorerT &storer) const {

View File

@ -64,7 +64,8 @@ class UdpReaderHelper {
} }
private: private:
enum : size_t { MAX_PACKET_SIZE = 2048, RESERVED_SIZE = MAX_PACKET_SIZE * 8 }; static constexpr size_t MAX_PACKET_SIZE = 2048;
static constexpr size_t RESERVED_SIZE = MAX_PACKET_SIZE * 8;
UdpMessage message_; UdpMessage message_;
BufferSlice buffer_; BufferSlice buffer_;
}; };
@ -98,7 +99,7 @@ class UdpReader {
} }
private: private:
enum : size_t { BUFFER_SIZE = 16 }; static constexpr size_t BUFFER_SIZE = 16;
std::array<UdpSocketFd::InboundMessage, BUFFER_SIZE> messages_; std::array<UdpSocketFd::InboundMessage, BUFFER_SIZE> messages_;
std::array<UdpReaderHelper, BUFFER_SIZE> helpers_; std::array<UdpReaderHelper, BUFFER_SIZE> helpers_;
}; };

View File

@ -170,7 +170,8 @@ class UdpSocketFdImpl : private Iocp::Callback {
UdpMessage to_receive_; UdpMessage to_receive_;
WSAMSG receive_message_; WSAMSG receive_message_;
UdpSocketReceiveHelper receive_helper_; UdpSocketReceiveHelper receive_helper_;
enum : size_t { MAX_PACKET_SIZE = 2048, RESERVED_SIZE = MAX_PACKET_SIZE * 8 }; static constexpr size_t MAX_PACKET_SIZE = 2048;
static constexpr size_t RESERVED_SIZE = MAX_PACKET_SIZE * 8;
BufferSlice receive_buffer_; BufferSlice receive_buffer_;
UdpMessage to_send_; UdpMessage to_send_;