Skip to content

Commit

Permalink
Merge dashpay#6513: refactor: make SEMToString / SEMFromString conste…
Browse files Browse the repository at this point in the history
…xpr 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
  • Loading branch information
PastaPastaPasta committed Dec 28, 2024
2 parents da1963d + 80f4537 commit 6310321
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,9 @@ static RPCHelpMan getnetworkinfo()
obj.pushKV("connections_mn", (int)node.connman->GetNodeCount(ConnectionDirection::Verified));
obj.pushKV("connections_mn_in", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedIn));
obj.pushKV("connections_mn_out", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedOut));
std::string sem_str = SEMToString(node.connman->GetSocketEventsMode());
std::string_view sem_str = SEMToString(node.connman->GetSocketEventsMode());
CHECK_NONFATAL(sem_str != "unknown");
obj.pushKV("socketevents", sem_str);
obj.pushKV("socketevents", std::string(sem_str));
}
obj.pushKV("networks", GetNetworksInfo());
obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));
Expand Down
14 changes: 6 additions & 8 deletions src/util/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ enum class SocketEventsMode : int8_t {
};

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

/* Converts string to SocketEventsMode value with additional check to report modes not compiled for as unknown */
static SocketEventsMode SEMFromString(const std::string str)
{
constexpr SocketEventsMode SEMFromString(std::string_view str) {
if (str == "select") { return SocketEventsMode::Select; }
#ifdef USE_POLL
else if (str == "poll") { return SocketEventsMode::Poll; }
if (str == "poll") { return SocketEventsMode::Poll; }
#endif /* USE_POLL */
#ifdef USE_EPOLL
else if (str == "epoll") { return SocketEventsMode::EPoll; }
if (str == "epoll") { return SocketEventsMode::EPoll; }
#endif /* USE_EPOLL */
#ifdef USE_KQUEUE
else if (str == "kqueue") { return SocketEventsMode::KQueue; }
if (str == "kqueue") { return SocketEventsMode::KQueue; }
#endif /* USE_KQUEUE */
else { return SocketEventsMode::Unknown; }
return SocketEventsMode::Unknown;
}

/**
Expand Down

0 comments on commit 6310321

Please sign in to comment.