Skip to content

Commit

Permalink
Add FOLLY_NODISCARD and noexcept in more places in ConnectionKey and …
Browse files Browse the repository at this point in the history
…PoolKey

Summary: As stated in the title.

Reviewed By: fadimounir, aditya-jalan

Differential Revision: D47687233

fbshipit-source-id: f151a8e660e88813de3e49ca0267c3dbd9458fe9
  • Loading branch information
Jay Edgar authored and facebook-github-bot committed Aug 2, 2023
1 parent d7a0740 commit e2828bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
32 changes: 15 additions & 17 deletions squangle/base/ConnectionKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,36 @@ ConnectionKey::ConnectionKey(
port_(port),
ignoreDbName_(ignore_db_name) {}

bool ConnectionKey::operator==(const ConnectionKey& rhs) const {
bool ConnectionKey::operator==(const ConnectionKey& rhs) const noexcept {
return hash_ == rhs.hash_ && host_ == rhs.host_ && port_ == rhs.port_ &&
(ignoreDbName_ || dbName_ == rhs.dbName_) && user_ == rhs.user_ &&
password_ == rhs.password_ && specialTag_ == rhs.specialTag_ &&
unixSocketPath_ == rhs.unixSocketPath_;
}

bool ConnectionKey::partialEqual(const ConnectionKey& rhs) const {
bool ConnectionKey::partialEqual(const ConnectionKey& rhs) const noexcept {
return partialHash_ == rhs.partialHash_ && host_ == rhs.host_ &&
port_ == rhs.port_ && user_ == rhs.user_ && password_ == rhs.password_ &&
specialTag_ == rhs.specialTag_ && unixSocketPath_ == rhs.unixSocketPath_;
}

std::string ConnectionKey::getDisplayString(bool level2) const {
if (unixSocketPath_.empty()) {
return folly::format(
"{} [{}] ({}@{}:{})",
level2 ? "" : dbName_,
specialTag_,
user_,
host_,
port_)
.str();
return folly::sformat(
"{} [{}] ({}@{}:{})",
level2 ? "" : dbName_,
specialTag_,
user_,
host_,
port_);
}

return folly::format(
"{} [{}] ({}@{})",
level2 ? "" : dbName_,
specialTag_,
user_,
unixSocketPath_)
.str();
return folly::sformat(
"{} [{}] ({}@{})",
level2 ? "" : dbName_,
specialTag_,
user_,
unixSocketPath_);
}
} // namespace mysql_client
} // namespace common
Expand Down
8 changes: 4 additions & 4 deletions squangle/base/ConnectionKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class ConnectionKey {
bool sp_ignore_db_name = false,
folly::StringPiece sp_unixSocketPath = "");

bool partialEqual(const ConnectionKey& rhs) const;
FOLLY_NODISCARD bool partialEqual(const ConnectionKey& rhs) const noexcept;

bool operator==(const ConnectionKey& rhs) const;
FOLLY_NODISCARD bool operator==(const ConnectionKey& rhs) const noexcept;

bool operator!=(const ConnectionKey& rhs) const {
FOLLY_NODISCARD bool operator!=(const ConnectionKey& rhs) const noexcept {
return !(*this == rhs);
}

Expand Down Expand Up @@ -73,7 +73,7 @@ class ConnectionKey {
return specialTag_;
}

std::string getDisplayString(bool level2 = false) const;
FOLLY_NODISCARD std::string getDisplayString(bool level2 = false) const;

private:
std::string host_;
Expand Down
17 changes: 9 additions & 8 deletions squangle/mysql_client/PoolKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,39 @@ class PoolKey {
full_hash_ = folly::hash::hash_combine(connKey_.hash(), options_hash_);
}

bool operator==(const PoolKey& rhs) const {
FOLLY_NODISCARD bool operator==(const PoolKey& rhs) const noexcept {
return full_hash_ == rhs.full_hash_ && options_hash_ == rhs.options_hash_ &&
connKey_ == rhs.connKey_;
}

bool operator!=(const PoolKey& rhs) const {
FOLLY_NODISCARD bool operator!=(const PoolKey& rhs) const noexcept {
return !(*this == rhs);
}

bool partialCompare(const PoolKey& rhs) const {
FOLLY_NODISCARD bool partialCompare(const PoolKey& rhs) const noexcept {
return partial_hash_ == rhs.partial_hash_ &&
options_hash_ == rhs.options_hash_ &&
connKey_.partialEqual(rhs.connKey_);
}

const ConnectionKey& getConnectionKey() const noexcept {
FOLLY_NODISCARD const ConnectionKey& getConnectionKey() const noexcept {
return connKey_;
}

const ConnectionOptions& getConnectionOptions() const noexcept {
FOLLY_NODISCARD const ConnectionOptions& getConnectionOptions()
const noexcept {
return connOptions_;
}

size_t getHash() const {
FOLLY_NODISCARD size_t getHash() const noexcept {
return full_hash_;
}

size_t getPartialHash() const {
FOLLY_NODISCARD size_t getPartialHash() const noexcept {
return partial_hash_;
}

size_t getOptionsHash() const {
FOLLY_NODISCARD size_t getOptionsHash() const noexcept {
return options_hash_;
}

Expand Down

0 comments on commit e2828bd

Please sign in to comment.