Commit 102ada09 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Treat underscores and dashes as equal in command names

parent 2771e3d5
Pipeline #283550 passed with stages
in 24 minutes and 11 seconds
......@@ -26,7 +26,7 @@ using namespace quarkdb;
std::map<std::string,
std::pair<RedisCommand, CommandType>,
caseInsensitiveComparator>
CommandComparator>
quarkdb::redis_cmd_map;
struct cmdMapInit {
......@@ -85,7 +85,7 @@ struct cmdMapInit {
redis_cmd_map["raft_heartbeat"] = {RedisCommand::RAFT_HEARTBEAT, CommandType::RAFT};
redis_cmd_map["raft_invalid_command"] = {RedisCommand::RAFT_INVALID_COMMAND, CommandType::RAFT};
redis_cmd_map["raft_fetch_last"] = {RedisCommand::RAFT_FETCH_LAST, CommandType::RAFT};
redis_cmd_map["activate-stale-reads"] = {RedisCommand::ACTIVATE_STALE_READS, CommandType::RAFT};
redis_cmd_map["activate_stale_reads"] = {RedisCommand::ACTIVATE_STALE_READS, CommandType::RAFT};
redis_cmd_map["quarkdb_info"] = {RedisCommand::QUARKDB_INFO, CommandType::QUARKDB};
redis_cmd_map["quarkdb_detach"] = {RedisCommand::QUARKDB_DETACH, CommandType::QUARKDB};
......@@ -96,7 +96,7 @@ struct cmdMapInit {
redis_cmd_map["quarkdb_cancel_resilvering"] = {RedisCommand::QUARKDB_CANCEL_RESILVERING, CommandType::QUARKDB};
redis_cmd_map["quarkdb_bulkload_finalize"] = {RedisCommand::QUARKDB_BULKLOAD_FINALIZE, CommandType::QUARKDB};
redis_cmd_map["quarkdb_invalid_command"] = {RedisCommand::QUARKDB_INVALID_COMMAND, CommandType::QUARKDB};
redis_cmd_map["recovery-info"] = {RedisCommand::RECOVERY_INFO, CommandType::QUARKDB};
redis_cmd_map["recovery_info"] = {RedisCommand::RECOVERY_INFO, CommandType::QUARKDB};
}
} cmd_map_init;
......@@ -113,11 +113,26 @@ enum class CommandType {
QUARKDB
};
struct caseInsensitiveComparator {
#define QDB_ALWAYS_INLINE __attribute__((always_inline))
struct CommandComparator {
QDB_ALWAYS_INLINE
char normalize(char c) const {
char ret = tolower(c);
if(ret == '-') {
ret = '_';
}
return ret;
}
bool operator() (const std::string& lhs, const std::string& rhs) const {
for(size_t i = 0; i < std::min(lhs.size(), rhs.size()); i++) {
if(tolower(lhs[i]) != tolower(rhs[i])) {
return tolower(lhs[i]) < tolower(rhs[i]);
char left = normalize(lhs[i]);
char right = normalize(rhs[i]);
if(left != right) {
return left < right;
}
}
return lhs.size() < rhs.size();
......@@ -126,7 +141,7 @@ struct caseInsensitiveComparator {
extern std::map<std::string,
std::pair<RedisCommand, CommandType>,
caseInsensitiveComparator>
CommandComparator>
redis_cmd_map;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment