mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
chore: get rid of ToUpper/ToLower mutations on arguments (#3950)
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
84e22aa658
commit
14220a6a20
7 changed files with 18 additions and 48 deletions
|
@ -276,12 +276,11 @@ OpResult<ScanOpts> ScanOpts::TryFrom(CmdArgList args) {
|
|||
ScanOpts scan_opts;
|
||||
|
||||
for (unsigned i = 0; i < args.size(); i += 2) {
|
||||
ToUpper(&args[i]);
|
||||
string_view opt = ArgS(args, i);
|
||||
if (i + 1 == args.size()) {
|
||||
return facade::OpStatus::SYNTAX_ERR;
|
||||
}
|
||||
|
||||
string opt = absl::AsciiStrToUpper(ArgS(args, i));
|
||||
if (opt == "COUNT") {
|
||||
if (!absl::SimpleAtoi(ArgS(args, i + 1), &scan_opts.limit)) {
|
||||
return facade::OpStatus::INVALID_INT;
|
||||
|
|
|
@ -109,18 +109,6 @@ std::ostream& operator<<(std::ostream& os, const GlobalState& state);
|
|||
|
||||
enum class TimeUnit : uint8_t { SEC, MSEC };
|
||||
|
||||
inline void ToUpper(const MutableSlice* val) {
|
||||
for (auto& c : *val) {
|
||||
c = absl::ascii_toupper(c);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ToLower(const MutableSlice* val) {
|
||||
for (auto& c : *val) {
|
||||
c = absl::ascii_tolower(c);
|
||||
}
|
||||
}
|
||||
|
||||
bool ParseHumanReadableBytes(std::string_view str, int64_t* num_bytes);
|
||||
bool ParseDouble(std::string_view src, double* value);
|
||||
|
||||
|
|
|
@ -370,7 +370,7 @@ DebugCmd::DebugCmd(ServerFamily* owner, ConnectionContext* cntx) : sf_(*owner),
|
|||
}
|
||||
|
||||
void DebugCmd::Run(CmdArgList args) {
|
||||
string_view subcmd = ArgS(args, 0);
|
||||
string subcmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
if (subcmd == "HELP") {
|
||||
string_view help_arr[] = {
|
||||
"DEBUG <subcommand> [<arg> [value] [opt] ...]. Subcommands are:",
|
||||
|
|
|
@ -1898,8 +1898,7 @@ void Service::Eval(CmdArgList args, ConnectionContext* cntx) {
|
|||
}
|
||||
|
||||
void Service::EvalSha(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToLower(&args[0]);
|
||||
string_view sha = ArgS(args, 0);
|
||||
string sha = absl::AsciiStrToLower(ArgS(args, 0));
|
||||
|
||||
BorrowedInterpreter interpreter{cntx};
|
||||
CallSHA(args, sha, interpreter, cntx);
|
||||
|
|
|
@ -92,7 +92,7 @@ MemoryCmd::MemoryCmd(ServerFamily* owner, ConnectionContext* cntx) : cntx_(cntx)
|
|||
}
|
||||
|
||||
void MemoryCmd::Run(CmdArgList args) {
|
||||
string_view sub_cmd = ArgS(args, 0);
|
||||
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
|
||||
if (sub_cmd == "HELP") {
|
||||
string_view help_arr[] = {
|
||||
|
|
|
@ -68,7 +68,7 @@ ScriptMgr::ScriptKey::ScriptKey(string_view sha) : array{} {
|
|||
}
|
||||
|
||||
void ScriptMgr::Run(CmdArgList args, ConnectionContext* cntx) {
|
||||
string_view subcmd = ArgS(args, 0);
|
||||
string subcmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
|
||||
if (subcmd == "HELP") {
|
||||
string_view kHelp[] = {
|
||||
|
|
|
@ -476,8 +476,7 @@ void ClientSetInfo(CmdArgList args, ConnectionContext* cntx) {
|
|||
return cntx->SendError("No connection");
|
||||
}
|
||||
|
||||
ToUpper(&args[0]);
|
||||
string_view type = ArgS(args, 0);
|
||||
string type = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
string_view val = ArgS(args, 1);
|
||||
|
||||
if (type == "LIB-NAME") {
|
||||
|
@ -510,8 +509,7 @@ void ClientKill(CmdArgList args, absl::Span<facade::Listener*> listeners, Connec
|
|||
};
|
||||
}
|
||||
} else if (args.size() == 2) {
|
||||
ToUpper(&args[0]);
|
||||
string_view filter_type = ArgS(args, 0);
|
||||
string filter_type = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
string_view filter_value = ArgS(args, 1);
|
||||
if (filter_type == "ADDR") {
|
||||
evaluator = [filter_value](facade::Connection* conn) {
|
||||
|
@ -1842,8 +1840,7 @@ void ServerFamily::Auth(CmdArgList args, ConnectionContext* cntx) {
|
|||
}
|
||||
|
||||
void ServerFamily::Client(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToUpper(&args[0]);
|
||||
string_view sub_cmd = ArgS(args, 0);
|
||||
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
CmdArgList sub_args = args.subspan(1);
|
||||
|
||||
if (sub_cmd == "SETNAME") {
|
||||
|
@ -1871,8 +1868,7 @@ void ServerFamily::Client(CmdArgList args, ConnectionContext* cntx) {
|
|||
}
|
||||
|
||||
void ServerFamily::Config(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToUpper(&args[0]);
|
||||
string_view sub_cmd = ArgS(args, 0);
|
||||
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
|
||||
if (sub_cmd == "HELP") {
|
||||
string_view help_arr[] = {
|
||||
|
@ -1896,8 +1892,7 @@ void ServerFamily::Config(CmdArgList args, ConnectionContext* cntx) {
|
|||
return cntx->SendError(WrongNumArgsError("config|set"));
|
||||
}
|
||||
|
||||
ToLower(&args[1]);
|
||||
string_view param = ArgS(args, 1);
|
||||
string param = absl::AsciiStrToLower(ArgS(args, 1));
|
||||
|
||||
ConfigRegistry::SetResult result = config_registry.Set(param, ArgS(args, 2));
|
||||
|
||||
|
@ -1954,16 +1949,12 @@ void ServerFamily::Config(CmdArgList args, ConnectionContext* cntx) {
|
|||
}
|
||||
|
||||
void ServerFamily::Debug(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToUpper(&args[0]);
|
||||
|
||||
DebugCmd dbg_cmd{this, cntx};
|
||||
|
||||
return dbg_cmd.Run(args);
|
||||
}
|
||||
|
||||
void ServerFamily::Memory(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToUpper(&args[0]);
|
||||
|
||||
MemoryCmd mem_cmd{this, cntx};
|
||||
|
||||
return mem_cmd.Run(args);
|
||||
|
@ -1986,8 +1977,7 @@ std::optional<ServerFamily::VersionBasename> ServerFamily::GetVersionAndBasename
|
|||
bool new_version = absl::GetFlag(FLAGS_df_snapshot_format);
|
||||
|
||||
if (args.size() >= 1) {
|
||||
ToUpper(&args[0]);
|
||||
string_view sub_cmd = ArgS(args, 0);
|
||||
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
if (sub_cmd == "DF") {
|
||||
new_version = true;
|
||||
} else if (sub_cmd == "RDB") {
|
||||
|
@ -2185,11 +2175,10 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
|
|||
return cntx->SendError(kSyntaxErr);
|
||||
}
|
||||
|
||||
string_view section;
|
||||
string section;
|
||||
|
||||
if (args.size() == 1) {
|
||||
ToUpper(&args[0]);
|
||||
section = ArgS(args, 0);
|
||||
section = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
}
|
||||
|
||||
string info;
|
||||
|
@ -2867,9 +2856,8 @@ void ServerFamily::ReplConf(CmdArgList args, ConnectionContext* cntx) {
|
|||
|
||||
for (unsigned i = 0; i < args.size(); i += 2) {
|
||||
DCHECK_LT(i + 1, args.size());
|
||||
ToUpper(&args[i]);
|
||||
|
||||
std::string_view cmd = ArgS(args, i);
|
||||
string cmd = absl::AsciiStrToUpper(ArgS(args, i));
|
||||
std::string_view arg = ArgS(args, i + 1);
|
||||
if (cmd == "CAPA") {
|
||||
if (arg == "dragonfly" && args.size() == 2 && i == 0) {
|
||||
|
@ -2994,8 +2982,6 @@ void ServerFamily::Role(CmdArgList args, ConnectionContext* cntx) {
|
|||
}
|
||||
|
||||
void ServerFamily::Script(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToUpper(&args.front());
|
||||
|
||||
script_mgr_->Run(std::move(args), cntx);
|
||||
}
|
||||
|
||||
|
@ -3010,8 +2996,7 @@ void ServerFamily::LastSave(CmdArgList args, ConnectionContext* cntx) {
|
|||
|
||||
void ServerFamily::Latency(CmdArgList args, ConnectionContext* cntx) {
|
||||
auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder());
|
||||
ToUpper(&args[0]);
|
||||
string_view sub_cmd = ArgS(args, 0);
|
||||
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
|
||||
if (sub_cmd == "LATEST") {
|
||||
return rb->SendEmptyArray();
|
||||
|
@ -3050,8 +3035,7 @@ void ServerFamily::Dfly(CmdArgList args, ConnectionContext* cntx) {
|
|||
}
|
||||
|
||||
void ServerFamily::SlowLog(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToUpper(&args[0]);
|
||||
string_view sub_cmd = ArgS(args, 0);
|
||||
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
|
||||
if (sub_cmd == "HELP") {
|
||||
string_view help[] = {
|
||||
|
@ -3095,8 +3079,8 @@ void ServerFamily::SlowLog(CmdArgList args, ConnectionContext* cntx) {
|
|||
}
|
||||
|
||||
void ServerFamily::Module(CmdArgList args, ConnectionContext* cntx) {
|
||||
ToUpper(&args[0]);
|
||||
if (ArgS(args, 0) != "LIST")
|
||||
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
|
||||
if (sub_cmd != "LIST")
|
||||
return cntx->SendError(kSyntaxErr);
|
||||
|
||||
auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue