From da2dcc4636fbfa0209e37c90c2bb4b883d47ec02 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 5 Jul 2026 16:37:49 +0200 Subject: [PATCH] Modernize the code to use C++11 constexpr and ranged-for Prefer constexpr to macros and ranged-for to index-based loops. --- src/common/sckipc.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/common/sckipc.cpp b/src/common/sckipc.cpp index b68c19f45d..29b1f4f2b0 100644 --- a/src/common/sckipc.cpp +++ b/src/common/sckipc.cpp @@ -88,7 +88,7 @@ enum IPCCode // A random header, which is used to detect a loss-of-sync on the IPC // data stream. The header is 24-bits, and the IPCCode above is sent in the // last 8 bits. -const wxUint32 IPCCodeHeader=0x439d9600; +constexpr wxUint32 IPCCodeHeader = 0x439d9600; } // anonymous namespace @@ -98,16 +98,16 @@ const wxUint32 IPCCodeHeader=0x439d9600; #include #endif // __UNIX_LIKE__ -#define wxNO_RETURN_MESSAGE nullptr +constexpr auto wxNO_RETURN_MESSAGE = nullptr; -const long wxIPCTimeout = 10; // socket timeout, in seconds +constexpr long wxIPCTimeout = 10; // socket timeout, in seconds // For IPC returning a char* buffer. wxWidgets docs say that the user is not // supposed to free the memory. Each buffer pointer is assigned to a list // sequentially, and the buffer memory is not freed until MAX_MSG_BUFFERS have // been assigned. -#define MAX_MSG_BUFFERS 2048 +constexpr int MAX_MSG_BUFFERS = 2048; // ---------------------------------------------------------------------------- @@ -152,17 +152,16 @@ class wxTCPEventHandler : public wxEvtHandler public: wxTCPEventHandler() : wxEvtHandler() { - for (int i = 0; i < MAX_MSG_BUFFERS; i++) - m_bufferList[i] = nullptr; + for ( auto& buf : m_bufferList ) + buf = nullptr; m_nextAvailable = 0; } ~wxTCPEventHandler() { - for (int i = 0; i < MAX_MSG_BUFFERS; i++) - if (m_bufferList[i]) - delete[] m_bufferList[i]; + for ( auto& buf : m_bufferList ) + delete[] buf; } void OnSocketInput(wxSocketEvent& event);