Commit 3c6f1f78 authored by Rosen Penev's avatar Rosen Penev Committed by Facebook Github Bot

Simplify boolean expressions (#1301)

Summary:
Found with readability-simplify-boolean-expr
Signed-off-by: default avatarRosen Penev <rosenp@gmail.com>
Pull Request resolved: https://github.com/facebook/folly/pull/1301

Reviewed By: yfeldblum

Differential Revision: D19302630

Pulled By: Orvid

fbshipit-source-id: 9833e4ab3fe93592fa8f868f6ed2d56a263949fe
parent 26dd59cd
...@@ -282,10 +282,7 @@ bool IPAddressV6::isIPv4Mapped() const { ...@@ -282,10 +282,7 @@ bool IPAddressV6::isIPv4Mapped() const {
} }
} }
// check if bytes 11 and 12 are 255 // check if bytes 11 and 12 are 255
if (by[10] == 0xff && by[11] == 0xff) { return by[10] == 0xff && by[11] == 0xff;
return true;
}
return false;
} }
// public // public
......
...@@ -312,10 +312,7 @@ bool StreamCodec::uncompressStream( ...@@ -312,10 +312,7 @@ bool StreamCodec::uncompressStream(
MutableByteRange& output, MutableByteRange& output,
StreamCodec::FlushOp flushOp) { StreamCodec::FlushOp flushOp) {
if (state_ == State::RESET && input.empty()) { if (state_ == State::RESET && input.empty()) {
if (uncompressedLength().value_or(0) == 0) { return uncompressedLength().value_or(0) == 0;
return true;
}
return false;
} }
// Handle input state transitions // Handle input state transitions
if (state_ == State::RESET) { if (state_ == State::RESET) {
......
...@@ -1020,14 +1020,16 @@ bool AsyncSSLSocket::willBlock( ...@@ -1020,14 +1020,16 @@ bool AsyncSSLSocket::willBlock(
// Register for read event if not already. // Register for read event if not already.
updateEventRegistration(EventHandler::READ, EventHandler::WRITE); updateEventRegistration(EventHandler::READ, EventHandler::WRITE);
return true; return true;
} else if (error == SSL_ERROR_WANT_WRITE) { }
if (error == SSL_ERROR_WANT_WRITE) {
VLOG(3) << "AsyncSSLSocket(fd=" << fd_ << ", state=" << int(state_) VLOG(3) << "AsyncSSLSocket(fd=" << fd_ << ", state=" << int(state_)
<< ", sslState=" << sslState_ << ", events=" << eventFlags_ << "): " << ", sslState=" << sslState_ << ", events=" << eventFlags_ << "): "
<< "SSL_ERROR_WANT_WRITE"; << "SSL_ERROR_WANT_WRITE";
// Register for write event if not already. // Register for write event if not already.
updateEventRegistration(EventHandler::WRITE, EventHandler::READ); updateEventRegistration(EventHandler::WRITE, EventHandler::READ);
return true; return true;
} else if ((false }
if ((false
#ifdef SSL_ERROR_WANT_ASYNC // OpenSSL 1.1.0 Async API #ifdef SSL_ERROR_WANT_ASYNC // OpenSSL 1.1.0 Async API
|| error == SSL_ERROR_WANT_ASYNC || error == SSL_ERROR_WANT_ASYNC
#endif #endif
...@@ -1964,7 +1966,7 @@ void AsyncSSLSocket::getSSLClientCiphers( ...@@ -1964,7 +1966,7 @@ void AsyncSSLSocket::getSSLClientCiphers(
bool convertToString) const { bool convertToString) const {
std::string ciphers; std::string ciphers;
if (parseClientHello_ == false || if (!parseClientHello_ ||
clientHelloInfo_->clientHelloCipherSuites_.empty()) { clientHelloInfo_->clientHelloCipherSuites_.empty()) {
clientCiphers = ""; clientCiphers = "";
return; return;
......
...@@ -733,7 +733,7 @@ NetworkSocket AsyncServerSocket::createSocket(int family) { ...@@ -733,7 +733,7 @@ NetworkSocket AsyncServerSocket::createSocket(int family) {
* TOS derived from the client's connect request * TOS derived from the client's connect request
*/ */
void AsyncServerSocket::setTosReflect(bool enable) { void AsyncServerSocket::setTosReflect(bool enable) {
if (!kIsLinux || enable == false) { if (!kIsLinux || !enable) {
tosReflect_ = false; tosReflect_ = false;
return; return;
} }
......
...@@ -895,7 +895,7 @@ bool AsyncSocket::setZeroCopy(bool enable) { ...@@ -895,7 +895,7 @@ bool AsyncSocket::setZeroCopy(bool enable) {
ret = netops::getsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &val, &optlen); ret = netops::getsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &val, &optlen);
if (!ret) { if (!ret) {
enable = val ? true : false; enable = val != 0;
} }
} }
......
...@@ -517,13 +517,10 @@ bool SSLContext::setRandomizedAdvertisedNextProtocols( ...@@ -517,13 +517,10 @@ bool SSLContext::setRandomizedAdvertisedNextProtocols(
// Client cannot really use randomized alpn // Client cannot really use randomized alpn
// Note that this function reverses the typical return value convention // Note that this function reverses the typical return value convention
// of openssl and returns 0 on success. // of openssl and returns 0 on success.
if (SSL_CTX_set_alpn_protos( return SSL_CTX_set_alpn_protos(
ctx_, ctx_,
advertisedNextProtocols_[0].protocols, advertisedNextProtocols_[0].protocols,
advertisedNextProtocols_[0].length) != 0) { advertisedNextProtocols_[0].length) == 0;
return false;
}
return true;
} }
void SSLContext::deleteNextProtocolsStrings() { void SSLContext::deleteNextProtocolsStrings() {
......
...@@ -288,11 +288,7 @@ bool checkTimeout( ...@@ -288,11 +288,7 @@ bool checkTimeout(
// On x86 Linux, sleep calls generally have precision only to the nearest // On x86 Linux, sleep calls generally have precision only to the nearest
// millisecond. The tolerance parameter lets users allow a few ms of slop. // millisecond. The tolerance parameter lets users allow a few ms of slop.
auto overrun = effectiveElapsedTime - expected; auto overrun = effectiveElapsedTime - expected;
if (overrun > tolerance) { return overrun <= tolerance;
return false;
}
return true;
} }
} // namespace folly } // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment