From ae8affe9fff64f9119b50cab409c47460d42b6e6 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 30 May 2025 20:53:22 +0800 Subject: perf(session): directly use m_bDeaf --- src/session.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/session.cpp b/src/session.cpp index 4cafd56..c537b25 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -1,9 +1,9 @@ -#include "session.hpp" #include "chatManager.hpp" #include "commandHandler.hpp" #include "format.hpp" #include "log.hpp" #include "server.hpp" +#include "session.hpp" #include "sessionManager.hpp" #include #include @@ -134,12 +134,11 @@ std::unique_ptr CSession::read() { } std::unique_ptr CSession::read(const std::string &msg, bool bypassDeaf) { - const auto deaf = isDeaf(); - if (bypassDeaf && deaf) - setDeaf(false); - write(NONEWLINE, "{}", msg, false); - if (bypassDeaf && deaf) - setDeaf(true); + if (bypassDeaf && m_bDeaf) + m_bDeaf = false; + write(NONEWLINE, "{}", msg); + if (bypassDeaf && m_bDeaf) + m_bDeaf = true; m_szReading = msg; return read(); } @@ -181,16 +180,16 @@ bool CSession::registerSession() { recvData->sanitize(); if (recvData->isEmpty()) { - setDeaf(false); + m_bDeaf = false; write("Name cannot be empty"); - setDeaf(true); + m_bDeaf = true; return registerSession(); } if (g_pSessionManager->nameExists(recvData->data)) { - setDeaf(false); + m_bDeaf = false; write("Name already exists"); - setDeaf(true); + m_bDeaf = true; return registerSession(); } @@ -200,7 +199,7 @@ bool CSession::registerSession() { g_pSessionManager->broadcast(NFormatter::fmt(NONEWLINE, "{} has joined the chat", m_name), this); - setDeaf(false); + m_bDeaf = false; return true; } @@ -215,14 +214,14 @@ bool CSession::isValid() { template bool CSession::write(std::format_string fmt, Args &&...args) { - if (isDeaf()) + if (m_bDeaf) return false; return write(NONE, fmt, std::forward(args)...); } template bool CSession::write(eFormatType type, std::format_string fmt, Args &&...args) { - if (isDeaf()) + if (m_bDeaf) return false; std::string msg = NFormatter::fmt(type, fmt, std::forward(args)...); -- cgit v1.2.3