chore: Combine unnessessary multi level if into less fewer checks

This commit is contained in:
sithlord48
2025-05-23 13:52:30 -04:00
committed by Nick Bolton
parent 6875969255
commit 9c56fa5dda
7 changed files with 33 additions and 58 deletions

View File

@ -166,10 +166,8 @@ void ArchNetworkBSD::closeSocketForRead(ArchSocket s)
{
assert(s != nullptr);
if (shutdown(s->m_fd, 0) == -1) {
if (errno != ENOTCONN) {
throwError(errno);
}
if ((shutdown(s->m_fd, 0) == -1) && (errno != ENOTCONN)) {
throwError(errno);
}
}
@ -177,10 +175,8 @@ void ArchNetworkBSD::closeSocketForWrite(ArchSocket s)
{
assert(s != nullptr);
if (shutdown(s->m_fd, 1) == -1) {
if (errno != ENOTCONN) {
throwError(errno);
}
if ((shutdown(s->m_fd, 1) == -1) && (errno != ENOTCONN)) {
throwError(errno);
}
}

View File

@ -134,13 +134,11 @@ void App::setupFileLogging()
void App::loggingFilterWarning() const
{
if (CLOG->getFilter() > CLOG->getConsoleMaxLevel()) {
if (argsBase().m_logFile == nullptr) {
LOG(
(CLOG_WARN "log messages above %s are NOT sent to console (use file logging)",
CLOG->getFilterName(CLOG->getConsoleMaxLevel()))
);
}
if ((CLOG->getFilter() > CLOG->getConsoleMaxLevel()) && (argsBase().m_logFile == nullptr)) {
LOG(
(CLOG_WARN "log messages above %s are NOT sent to console (use file logging)",
CLOG->getFilterName(CLOG->getConsoleMaxLevel()))
);
}
}

View File

@ -25,15 +25,11 @@ void FingerprintDatabase::readStream(QTextStream &in)
if (!in.device() && !in.string())
return;
if (in.device()) {
if (!in.device()->isReadable())
return;
}
if (in.device() && !in.device()->isReadable())
return;
if (in.string()) {
if (in.string()->isEmpty())
return;
}
if (in.string() && in.string()->isEmpty())
return;
QString line;
while (!in.atEnd()) {
@ -63,10 +59,8 @@ bool FingerprintDatabase::writeStream(QTextStream &out)
if (!out.device() && !out.string())
return false;
if (out.device()) {
if (!out.device()->isWritable())
return false;
}
if (out.device() && !out.device()->isWritable())
return false;
for (const auto &fingerprint : std::as_const(m_fingerprints)) {
out << fingerprint.toDbLine() << "\n";

View File

@ -443,12 +443,10 @@ int SecureSocket::secureAccept(int socket)
// If not fatal and no retry, state is good
if (retry == 0) {
if (m_securityLevel == SecurityLevel::PeerAuth) {
if (!verifyCertFingerprint(Settings::tlsTrustedClientsDb())) {
retry = 0;
disconnect();
return -1; // Fail
}
if (m_securityLevel == SecurityLevel::PeerAuth && !verifyCertFingerprint(Settings::tlsTrustedClientsDb())) {
retry = 0;
disconnect();
return -1; // Fail
}
m_secureReady = true;
LOG((CLOG_INFO "accepted secure socket"));

View File

@ -108,12 +108,10 @@ void SocketMultiplexer::removeSocket(ISocket *socket)
// remove job. rather than removing it from the map we put nullptr
// in the list instead so the order of jobs in the list continues
// to match the order of jobs in pfds in serviceThread().
if (SocketJobMap::iterator i = m_socketJobMap.find(socket); i != m_socketJobMap.end()) {
if (*(i->second) != nullptr) {
delete *(i->second);
*(i->second) = nullptr;
m_update = true;
}
if (SocketJobMap::iterator i = m_socketJobMap.find(socket); i != m_socketJobMap.end() && (*(i->second) != nullptr)) {
delete *(i->second);
*(i->second) = nullptr;
m_update = true;
}
// unlock the job list

View File

@ -1050,10 +1050,8 @@ void XWindowsScreen::openIM()
XIMStyle style = 0;
for (unsigned short i = 0; i < styles->count_styles; ++i) {
style = styles->supported_styles[i];
if ((style & XIMPreeditNothing) != 0) {
if ((style & (XIMStatusNothing | XIMStatusNone)) != 0) {
break;
}
if (((style & XIMPreeditNothing) != 0) && ((style & (XIMStatusNothing | XIMStatusNone)) != 0)) {
break;
}
}
XFree(styles);
@ -1148,11 +1146,8 @@ void XWindowsScreen::handleSystemEvent(const Event &event, void *)
// this is a hot key
onHotKey(xevent->xkey, isRepeat);
return;
} else if (!m_isOnScreen) {
// this might be a hot key
if (onHotKey(xevent->xkey, isRepeat)) {
return;
}
} else if (!m_isOnScreen && onHotKey(xevent->xkey, isRepeat)) {
return;
}
bool down = (isRepeat || xevent->type == KeyPress);

View File

@ -65,11 +65,9 @@ XWindowsScreenSaver::XWindowsScreenSaver(Display *display, Window window, void *
#if HAVE_X11_EXTENSIONS_DPMS_H
int eventBase;
int errorBase;
if (DPMSQueryExtension(m_display, &eventBase, &errorBase)) {
if (DPMSCapable(m_display)) {
// we have DPMS
m_dpms = true;
}
if (DPMSQueryExtension(m_display, &eventBase, &errorBase) && DPMSCapable(m_display)) {
// we have DPMS
m_dpms = true;
}
#endif
@ -159,11 +157,9 @@ bool XWindowsScreenSaver::handleXEvent(const XEvent *xevent)
break;
case PropertyNotify:
if (xevent->xproperty.state == PropertyNewValue) {
if (isXScreenSaver(xevent->xproperty.window)) {
// found the xscreensaver
setXScreenSaver(xevent->xcreatewindow.window);
}
if (xevent->xproperty.state == PropertyNewValue && isXScreenSaver(xevent->xproperty.window)) {
// found the xscreensaver
setXScreenSaver(xevent->xcreatewindow.window);
}
break;