Skip to content

Commit 6310321

Browse files
Merge #6513: refactor: make SEMToString / SEMFromString constexpr by using string_view
80f4537 refactor: make SEMToString / SEMFromString constexpr by using string_view (Pasta) Pull request description: ## Issue being fixed or feature implemented Apple clang version 16.0.0 (clang-1600.0.26.6) reports warnings such as: ``` ./util/sock.h:32:20: warning: unused function 'SEMToString' [-Wunused-function] 32 | static std::string SEMToString(const SocketEventsMode val) | ^~~~~~~~~~~ ./util/sock.h:55:25: warning: unused function 'SEMFromString' [-Wunused-function] 55 | static SocketEventsMode SEMFromString(const std::string str) | ^~~~~~~~~~~~~ ``` ## What was done? Converted these functions from static to constexpr, this results in these warnings being resolved ## How Has This Been Tested? Compiled ## Breaking Changes None ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 80f4537 Tree-SHA512: 1b44ec2bc02da5c861d7c863c05f76071006d4f6e4188d81e8e69277b6894a0073c64e6e98d467380b7df541d75df9154826399ca0b97bccd7c9fc781adacdd1
2 parents da1963d + 80f4537 commit 6310321

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/rpc/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,9 @@ static RPCHelpMan getnetworkinfo()
688688
obj.pushKV("connections_mn", (int)node.connman->GetNodeCount(ConnectionDirection::Verified));
689689
obj.pushKV("connections_mn_in", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedIn));
690690
obj.pushKV("connections_mn_out", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedOut));
691-
std::string sem_str = SEMToString(node.connman->GetSocketEventsMode());
691+
std::string_view sem_str = SEMToString(node.connman->GetSocketEventsMode());
692692
CHECK_NONFATAL(sem_str != "unknown");
693-
obj.pushKV("socketevents", sem_str);
693+
obj.pushKV("socketevents", std::string(sem_str));
694694
}
695695
obj.pushKV("networks", GetNetworksInfo());
696696
obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));

src/util/sock.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ enum class SocketEventsMode : int8_t {
2929
};
3030

3131
/* Converts SocketEventsMode value to string with additional check to report modes not compiled for as unknown */
32-
static std::string SEMToString(const SocketEventsMode val)
33-
{
32+
constexpr std::string_view SEMToString(const SocketEventsMode val) {
3433
switch (val) {
3534
case (SocketEventsMode::Select):
3635
return "select";
@@ -52,19 +51,18 @@ static std::string SEMToString(const SocketEventsMode val)
5251
}
5352

5453
/* Converts string to SocketEventsMode value with additional check to report modes not compiled for as unknown */
55-
static SocketEventsMode SEMFromString(const std::string str)
56-
{
54+
constexpr SocketEventsMode SEMFromString(std::string_view str) {
5755
if (str == "select") { return SocketEventsMode::Select; }
5856
#ifdef USE_POLL
59-
else if (str == "poll") { return SocketEventsMode::Poll; }
57+
if (str == "poll") { return SocketEventsMode::Poll; }
6058
#endif /* USE_POLL */
6159
#ifdef USE_EPOLL
62-
else if (str == "epoll") { return SocketEventsMode::EPoll; }
60+
if (str == "epoll") { return SocketEventsMode::EPoll; }
6361
#endif /* USE_EPOLL */
6462
#ifdef USE_KQUEUE
65-
else if (str == "kqueue") { return SocketEventsMode::KQueue; }
63+
if (str == "kqueue") { return SocketEventsMode::KQueue; }
6664
#endif /* USE_KQUEUE */
67-
else { return SocketEventsMode::Unknown; }
65+
return SocketEventsMode::Unknown;
6866
}
6967

7068
/**

0 commit comments

Comments
 (0)