From 51cfcb6369c5fdde83cb9196f4d30fc4f5faf0f0 Mon Sep 17 00:00:00 2001 From: PragmaTwice Date: Mon, 13 Mar 2023 11:12:06 +0800 Subject: [PATCH] Use inline to replace extern global constants --- src/config/config.cc | 7 +++---- src/config/config.h | 2 +- src/storage/redis_metadata.cc | 4 +--- src/storage/redis_metadata.h | 4 ++-- src/storage/storage.cc | 13 +------------ src/storage/storage.h | 16 ++++++++-------- src/storage/table_properties_collector.h | 2 +- 7 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/config/config.cc b/src/config/config.cc index 63e91ce592d..4e99b9c8250 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -39,11 +39,10 @@ #include "server/server.h" #include "status.h" -const char *kDefaultNamespace = "__namespace"; -const char *kDefaultBindAddress = "127.0.0.1"; +constexpr const char *kDefaultBindAddress = "127.0.0.1"; -const char *errBlobDbNotEnabled = "Must set rocksdb.enable_blob_files to yes first."; -const char *errLevelCompactionDynamicLevelBytesNotSet = +constexpr const char *errBlobDbNotEnabled = "Must set rocksdb.enable_blob_files to yes first."; +constexpr const char *errLevelCompactionDynamicLevelBytesNotSet = "Must set rocksdb.level_compaction_dynamic_level_bytes yes first."; configEnum compression_types[] = { diff --git a/src/config/config.h b/src/config/config.h index 2cd8f595583..6a3d2e27e7d 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -51,7 +51,7 @@ constexpr const size_t MiB = 1024L * KiB; constexpr const size_t GiB = 1024L * MiB; constexpr const uint32_t kDefaultPort = 6666; -extern const char *kDefaultNamespace; +constexpr const char *kDefaultNamespace = "__namespace"; struct CompactionCheckerRange { public: diff --git a/src/storage/redis_metadata.cc b/src/storage/redis_metadata.cc index 7b92a6034a7..717fe3c86fc 100644 --- a/src/storage/redis_metadata.cc +++ b/src/storage/redis_metadata.cc @@ -36,9 +36,7 @@ const int VersionCounterBits = 11; static std::atomic version_counter_ = {0}; -const char *kErrMsgWrongType = "WRONGTYPE Operation against a key holding the wrong kind of value"; -const char *kErrMsgKeyExpired = "the key was expired"; -const char *kErrMetadataTooShort = "metadata is too short"; +constexpr const char *kErrMetadataTooShort = "metadata is too short"; InternalKey::InternalKey(Slice input, bool slot_id_encoded) : slot_id_encoded_(slot_id_encoded) { uint32_t key_size = 0; diff --git a/src/storage/redis_metadata.h b/src/storage/redis_metadata.h index e4fa23a0d49..6550c569e44 100644 --- a/src/storage/redis_metadata.h +++ b/src/storage/redis_metadata.h @@ -59,8 +59,8 @@ enum RedisCommand { const std::vector RedisTypeNames = {"none", "string", "hash", "list", "set", "zset", "bitmap", "sortedint", "stream"}; -extern const char *kErrMsgWrongType; -extern const char *kErrMsgKeyExpired; +constexpr const char *kErrMsgWrongType = "WRONGTYPE Operation against a key holding the wrong kind of value"; +constexpr const char *kErrMsgKeyExpired = "the key was expired"; using rocksdb::Slice; diff --git a/src/storage/storage.cc b/src/storage/storage.cc index 3afeaabf815..c1a44a7830c 100644 --- a/src/storage/storage.cc +++ b/src/storage/storage.cc @@ -51,18 +51,7 @@ namespace Engine { -const char *kPubSubColumnFamilyName = "pubsub"; -const char *kZSetScoreColumnFamilyName = "zset_score"; -const char *kMetadataColumnFamilyName = "metadata"; -const char *kSubkeyColumnFamilyName = "default"; -const char *kPropagateColumnFamilyName = "propagate"; -const char *kStreamColumnFamilyName = "stream"; - -const char *kPropagateScriptCommand = "script"; - -const char *kLuaFunctionPrefix = "lua_f_"; - -const char *kReplicationIdKey = "replication_id_"; +constexpr const char *kReplicationIdKey = "replication_id_"; const int64_t kIORateLimitMaxMb = 1024000; diff --git a/src/storage/storage.h b/src/storage/storage.h index 194c428aaf5..c62499e7feb 100644 --- a/src/storage/storage.h +++ b/src/storage/storage.h @@ -53,16 +53,16 @@ enum ColumnFamilyID { namespace Engine { -extern const char *kPubSubColumnFamilyName; -extern const char *kZSetScoreColumnFamilyName; -extern const char *kMetadataColumnFamilyName; -extern const char *kSubkeyColumnFamilyName; -extern const char *kPropagateColumnFamilyName; -extern const char *kStreamColumnFamilyName; +constexpr const char *kPubSubColumnFamilyName = "pubsub"; +constexpr const char *kZSetScoreColumnFamilyName = "zset_score"; +constexpr const char *kMetadataColumnFamilyName = "metadata"; +constexpr const char *kSubkeyColumnFamilyName = "default"; +constexpr const char *kPropagateColumnFamilyName = "propagate"; +constexpr const char *kStreamColumnFamilyName = "stream"; -extern const char *kPropagateScriptCommand; +constexpr const char *kPropagateScriptCommand = "script"; -extern const char *kLuaFunctionPrefix; +constexpr const char *kLuaFunctionPrefix = "lua_f_"; class Storage { public: diff --git a/src/storage/table_properties_collector.h b/src/storage/table_properties_collector.h index c7ac1c3c490..a0dfd0dfb13 100644 --- a/src/storage/table_properties_collector.h +++ b/src/storage/table_properties_collector.h @@ -62,5 +62,5 @@ class CompactOnExpiredTableCollectorFactory : public rocksdb::TablePropertiesCol float trigger_threshold_ = 0.3; }; -extern std::shared_ptr NewCompactOnExpiredTableCollectorFactory( +std::shared_ptr NewCompactOnExpiredTableCollectorFactory( const std::string &cf_name, float trigger_threshold);