Skip to content

Commit 14220a6

Browse files
authored
chore: get rid of ToUpper/ToLower mutations on arguments (#3950)
Signed-off-by: Roman Gershman <[email protected]>
1 parent 84e22aa commit 14220a6

File tree

7 files changed

+18
-48
lines changed

7 files changed

+18
-48
lines changed

src/server/common.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,11 @@ OpResult<ScanOpts> ScanOpts::TryFrom(CmdArgList args) {
276276
ScanOpts scan_opts;
277277

278278
for (unsigned i = 0; i < args.size(); i += 2) {
279-
ToUpper(&args[i]);
280-
string_view opt = ArgS(args, i);
281279
if (i + 1 == args.size()) {
282280
return facade::OpStatus::SYNTAX_ERR;
283281
}
284282

283+
string opt = absl::AsciiStrToUpper(ArgS(args, i));
285284
if (opt == "COUNT") {
286285
if (!absl::SimpleAtoi(ArgS(args, i + 1), &scan_opts.limit)) {
287286
return facade::OpStatus::INVALID_INT;

src/server/common.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,6 @@ std::ostream& operator<<(std::ostream& os, const GlobalState& state);
109109

110110
enum class TimeUnit : uint8_t { SEC, MSEC };
111111

112-
inline void ToUpper(const MutableSlice* val) {
113-
for (auto& c : *val) {
114-
c = absl::ascii_toupper(c);
115-
}
116-
}
117-
118-
inline void ToLower(const MutableSlice* val) {
119-
for (auto& c : *val) {
120-
c = absl::ascii_tolower(c);
121-
}
122-
}
123-
124112
bool ParseHumanReadableBytes(std::string_view str, int64_t* num_bytes);
125113
bool ParseDouble(std::string_view src, double* value);
126114

src/server/debugcmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ DebugCmd::DebugCmd(ServerFamily* owner, ConnectionContext* cntx) : sf_(*owner),
370370
}
371371

372372
void DebugCmd::Run(CmdArgList args) {
373-
string_view subcmd = ArgS(args, 0);
373+
string subcmd = absl::AsciiStrToUpper(ArgS(args, 0));
374374
if (subcmd == "HELP") {
375375
string_view help_arr[] = {
376376
"DEBUG <subcommand> [<arg> [value] [opt] ...]. Subcommands are:",

src/server/main_service.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,8 +1898,7 @@ void Service::Eval(CmdArgList args, ConnectionContext* cntx) {
18981898
}
18991899

19001900
void Service::EvalSha(CmdArgList args, ConnectionContext* cntx) {
1901-
ToLower(&args[0]);
1902-
string_view sha = ArgS(args, 0);
1901+
string sha = absl::AsciiStrToLower(ArgS(args, 0));
19031902

19041903
BorrowedInterpreter interpreter{cntx};
19051904
CallSHA(args, sha, interpreter, cntx);

src/server/memory_cmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ MemoryCmd::MemoryCmd(ServerFamily* owner, ConnectionContext* cntx) : cntx_(cntx)
9292
}
9393

9494
void MemoryCmd::Run(CmdArgList args) {
95-
string_view sub_cmd = ArgS(args, 0);
95+
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
9696

9797
if (sub_cmd == "HELP") {
9898
string_view help_arr[] = {

src/server/script_mgr.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ScriptMgr::ScriptKey::ScriptKey(string_view sha) : array{} {
6868
}
6969

7070
void ScriptMgr::Run(CmdArgList args, ConnectionContext* cntx) {
71-
string_view subcmd = ArgS(args, 0);
71+
string subcmd = absl::AsciiStrToUpper(ArgS(args, 0));
7272

7373
if (subcmd == "HELP") {
7474
string_view kHelp[] = {

src/server/server_family.cc

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ void ClientSetInfo(CmdArgList args, ConnectionContext* cntx) {
476476
return cntx->SendError("No connection");
477477
}
478478

479-
ToUpper(&args[0]);
480-
string_view type = ArgS(args, 0);
479+
string type = absl::AsciiStrToUpper(ArgS(args, 0));
481480
string_view val = ArgS(args, 1);
482481

483482
if (type == "LIB-NAME") {
@@ -510,8 +509,7 @@ void ClientKill(CmdArgList args, absl::Span<facade::Listener*> listeners, Connec
510509
};
511510
}
512511
} else if (args.size() == 2) {
513-
ToUpper(&args[0]);
514-
string_view filter_type = ArgS(args, 0);
512+
string filter_type = absl::AsciiStrToUpper(ArgS(args, 0));
515513
string_view filter_value = ArgS(args, 1);
516514
if (filter_type == "ADDR") {
517515
evaluator = [filter_value](facade::Connection* conn) {
@@ -1842,8 +1840,7 @@ void ServerFamily::Auth(CmdArgList args, ConnectionContext* cntx) {
18421840
}
18431841

18441842
void ServerFamily::Client(CmdArgList args, ConnectionContext* cntx) {
1845-
ToUpper(&args[0]);
1846-
string_view sub_cmd = ArgS(args, 0);
1843+
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
18471844
CmdArgList sub_args = args.subspan(1);
18481845

18491846
if (sub_cmd == "SETNAME") {
@@ -1871,8 +1868,7 @@ void ServerFamily::Client(CmdArgList args, ConnectionContext* cntx) {
18711868
}
18721869

18731870
void ServerFamily::Config(CmdArgList args, ConnectionContext* cntx) {
1874-
ToUpper(&args[0]);
1875-
string_view sub_cmd = ArgS(args, 0);
1871+
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
18761872

18771873
if (sub_cmd == "HELP") {
18781874
string_view help_arr[] = {
@@ -1896,8 +1892,7 @@ void ServerFamily::Config(CmdArgList args, ConnectionContext* cntx) {
18961892
return cntx->SendError(WrongNumArgsError("config|set"));
18971893
}
18981894

1899-
ToLower(&args[1]);
1900-
string_view param = ArgS(args, 1);
1895+
string param = absl::AsciiStrToLower(ArgS(args, 1));
19011896

19021897
ConfigRegistry::SetResult result = config_registry.Set(param, ArgS(args, 2));
19031898

@@ -1954,16 +1949,12 @@ void ServerFamily::Config(CmdArgList args, ConnectionContext* cntx) {
19541949
}
19551950

19561951
void ServerFamily::Debug(CmdArgList args, ConnectionContext* cntx) {
1957-
ToUpper(&args[0]);
1958-
19591952
DebugCmd dbg_cmd{this, cntx};
19601953

19611954
return dbg_cmd.Run(args);
19621955
}
19631956

19641957
void ServerFamily::Memory(CmdArgList args, ConnectionContext* cntx) {
1965-
ToUpper(&args[0]);
1966-
19671958
MemoryCmd mem_cmd{this, cntx};
19681959

19691960
return mem_cmd.Run(args);
@@ -1986,8 +1977,7 @@ std::optional<ServerFamily::VersionBasename> ServerFamily::GetVersionAndBasename
19861977
bool new_version = absl::GetFlag(FLAGS_df_snapshot_format);
19871978

19881979
if (args.size() >= 1) {
1989-
ToUpper(&args[0]);
1990-
string_view sub_cmd = ArgS(args, 0);
1980+
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
19911981
if (sub_cmd == "DF") {
19921982
new_version = true;
19931983
} else if (sub_cmd == "RDB") {
@@ -2185,11 +2175,10 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
21852175
return cntx->SendError(kSyntaxErr);
21862176
}
21872177

2188-
string_view section;
2178+
string section;
21892179

21902180
if (args.size() == 1) {
2191-
ToUpper(&args[0]);
2192-
section = ArgS(args, 0);
2181+
section = absl::AsciiStrToUpper(ArgS(args, 0));
21932182
}
21942183

21952184
string info;
@@ -2867,9 +2856,8 @@ void ServerFamily::ReplConf(CmdArgList args, ConnectionContext* cntx) {
28672856

28682857
for (unsigned i = 0; i < args.size(); i += 2) {
28692858
DCHECK_LT(i + 1, args.size());
2870-
ToUpper(&args[i]);
28712859

2872-
std::string_view cmd = ArgS(args, i);
2860+
string cmd = absl::AsciiStrToUpper(ArgS(args, i));
28732861
std::string_view arg = ArgS(args, i + 1);
28742862
if (cmd == "CAPA") {
28752863
if (arg == "dragonfly" && args.size() == 2 && i == 0) {
@@ -2994,8 +2982,6 @@ void ServerFamily::Role(CmdArgList args, ConnectionContext* cntx) {
29942982
}
29952983

29962984
void ServerFamily::Script(CmdArgList args, ConnectionContext* cntx) {
2997-
ToUpper(&args.front());
2998-
29992985
script_mgr_->Run(std::move(args), cntx);
30002986
}
30012987

@@ -3010,8 +2996,7 @@ void ServerFamily::LastSave(CmdArgList args, ConnectionContext* cntx) {
30102996

30112997
void ServerFamily::Latency(CmdArgList args, ConnectionContext* cntx) {
30122998
auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder());
3013-
ToUpper(&args[0]);
3014-
string_view sub_cmd = ArgS(args, 0);
2999+
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
30153000

30163001
if (sub_cmd == "LATEST") {
30173002
return rb->SendEmptyArray();
@@ -3050,8 +3035,7 @@ void ServerFamily::Dfly(CmdArgList args, ConnectionContext* cntx) {
30503035
}
30513036

30523037
void ServerFamily::SlowLog(CmdArgList args, ConnectionContext* cntx) {
3053-
ToUpper(&args[0]);
3054-
string_view sub_cmd = ArgS(args, 0);
3038+
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
30553039

30563040
if (sub_cmd == "HELP") {
30573041
string_view help[] = {
@@ -3095,8 +3079,8 @@ void ServerFamily::SlowLog(CmdArgList args, ConnectionContext* cntx) {
30953079
}
30963080

30973081
void ServerFamily::Module(CmdArgList args, ConnectionContext* cntx) {
3098-
ToUpper(&args[0]);
3099-
if (ArgS(args, 0) != "LIST")
3082+
string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0));
3083+
if (sub_cmd != "LIST")
31003084
return cntx->SendError(kSyntaxErr);
31013085

31023086
auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder());

0 commit comments

Comments
 (0)