From c49ea100550a64b92857e7792bdd472514b9c162 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 3 Feb 2022 13:03:53 +0100 Subject: [PATCH] Migrate static data class members into static data namespace members MSVC linker can't merge former, but can the later ones. Signed-off-by: Simon Rozman --- include/WinStd/Base64.h | 34 ++++++++++++------------------- include/WinStd/EAP.h | 8 ++++---- include/WinStd/ETW.h | 45 +++++++++++++++++++---------------------- 3 files changed, 38 insertions(+), 49 deletions(-) diff --git a/include/WinStd/Base64.h b/include/WinStd/Base64.h index 097ab9ee..59fcc69e 100644 --- a/include/WinStd/Base64.h +++ b/include/WinStd/Base64.h @@ -111,10 +111,10 @@ namespace winstd template inline void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out) { - out += lookup[ buf[0] >> 2 ]; - out += lookup[((buf[0] << 4) | (buf[1] >> 4)) & 0x3f]; - out += lookup[((buf[1] << 2) | (buf[2] >> 6)) & 0x3f]; - out += lookup[ buf[2] & 0x3f]; + out += base64_enc_lookup[ buf[0] >> 2 ]; + out += base64_enc_lookup[((buf[0] << 4) | (buf[1] >> 4)) & 0x3f]; + out += base64_enc_lookup[((buf[1] << 2) | (buf[2] >> 6)) & 0x3f]; + out += base64_enc_lookup[ buf[2] & 0x3f]; } @@ -125,18 +125,18 @@ namespace winstd inline void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_ size_t size) { if (size > 0) { - out += lookup[buf[0] >> 2]; + out += base64_enc_lookup[buf[0] >> 2]; if (size > 1) { - out += lookup[((buf[0] << 4) | (buf[1] >> 4)) & 0x3f]; + out += base64_enc_lookup[((buf[0] << 4) | (buf[1] >> 4)) & 0x3f]; if (size > 2) { - out += lookup[((buf[1] << 2) | (buf[2] >> 6)) & 0x3f]; - out += lookup[buf[2] & 0x3f]; + out += base64_enc_lookup[((buf[1] << 2) | (buf[2] >> 6)) & 0x3f]; + out += base64_enc_lookup[buf[2] & 0x3f]; } else { - out += lookup[(buf[1] << 2) & 0x3f]; + out += base64_enc_lookup[(buf[1] << 2) & 0x3f]; out += '='; } } else { - out += lookup[(buf[0] << 4) & 0x3f]; + out += base64_enc_lookup[(buf[0] << 4) & 0x3f]; out += '='; out += '='; } @@ -152,15 +152,11 @@ namespace winstd protected: unsigned char buf[3]; ///< Internal buffer size_t num; ///< Number of bytes used in `buf` - - /// \cond internal - static const char lookup[64]; - /// \endcond }; /// \cond internal - const char base64_enc::lookup[64] = { + static const char base64_enc_lookup[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', @@ -222,7 +218,7 @@ namespace winstd break; int x = data[i]; - if ((buf[num] = x < _countof(lookup) ? lookup[x] : 255) != 255) + if ((buf[num] = x < _countof(base64_dec_lookup) ? base64_dec_lookup[x] : 255) != 255) num++; } } @@ -273,15 +269,11 @@ namespace winstd protected: unsigned char buf[4]; ///< Internal buffer size_t num; ///< Number of bytes used in `buf` - - /// \cond internal - static const unsigned char lookup[256]; - /// \endcond }; /// \cond internal - const unsigned char base64_dec::lookup[256] = { + static const unsigned char base64_dec_lookup[256] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ /* 0 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, /* 1 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, diff --git a/include/WinStd/EAP.h b/include/WinStd/EAP.h index bc0b319e..0f90f1d8 100644 --- a/include/WinStd/EAP.h +++ b/include/WinStd/EAP.h @@ -363,13 +363,13 @@ namespace winstd dwLength = dwLengthNew; pValue = p; } - - public: - static const EAP_ATTRIBUTE blank; ///< Blank EAP attribute }; #pragma warning(pop) - const EAP_ATTRIBUTE eap_attr::blank = {}; + /// + /// Blank EAP attribute + /// + static const EAP_ATTRIBUTE blank_eap_attr = {}; /// diff --git a/include/WinStd/ETW.h b/include/WinStd/ETW.h index 843b5911..7dc7b07c 100644 --- a/include/WinStd/ETW.h +++ b/include/WinStd/ETW.h @@ -250,15 +250,12 @@ namespace winstd { EventDataDescCreate(this, data, size); } - - - /// - /// Blank event data used as terminator. - /// - static const event_data blank; }; - const event_data event_data::blank; + /// + /// Blank event data used as terminator. + /// + static const event_data blank_event_data; /// @@ -540,7 +537,7 @@ namespace winstd /// /// Writes an event with one or more parameter. /// - /// \note The list must be terminated with `winstd::event_data::blank`. + /// \note The list must be terminated with `winstd::blank_event_data`. /// /// \return /// - `ERROR_SUCCESS` when write succeeds; @@ -553,9 +550,9 @@ namespace winstd assert(m_h != invalid); // The first argument (param1) is outside of varadic argument list. - if (param1.Ptr == winstd::event_data::blank.Ptr && - param1.Size == winstd::event_data::blank.Size && - param1.Reserved == winstd::event_data::blank.Reserved) + if (param1.Ptr == winstd::blank_event_data.Ptr && + param1.Size == winstd::blank_event_data.Size && + param1.Reserved == winstd::blank_event_data.Reserved) return EventWrite(m_h, EventDescriptor, 0, NULL); va_list arg; @@ -567,9 +564,9 @@ namespace winstd // Preallocate array. for (param_count = 1; param_count < MAX_EVENT_DATA_DESCRIPTORS; param_count++) { const EVENT_DATA_DESCRIPTOR &p = va_arg(arg, const EVENT_DATA_DESCRIPTOR); - if (p.Ptr == winstd::event_data::blank.Ptr && - p.Size == winstd::event_data::blank.Size && - p.Reserved == winstd::event_data::blank.Reserved) break; + if (p.Ptr == winstd::blank_event_data.Ptr && + p.Size == winstd::blank_event_data.Size && + p.Reserved == winstd::blank_event_data.Reserved) break; } params.reserve(param_count); @@ -578,9 +575,9 @@ namespace winstd params.push_back(param1); for (;;) { const EVENT_DATA_DESCRIPTOR &p = va_arg(arg, const EVENT_DATA_DESCRIPTOR); - if (p.Ptr == winstd::event_data::blank.Ptr && - p.Size == winstd::event_data::blank.Size && - p.Reserved == winstd::event_data::blank.Reserved) break; + if (p.Ptr == winstd::blank_event_data.Ptr && + p.Size == winstd::blank_event_data.Size && + p.Reserved == winstd::blank_event_data.Reserved) break; params.push_back(p); } @@ -595,7 +592,7 @@ namespace winstd /// /// Writes an event with variable number of parameters. /// - /// \note The list must be terminated with `winstd::event_data::blank`. + /// \note The list must be terminated with `winstd::blank_event_data`. /// /// \return /// - `ERROR_SUCCESS` when write succeeds; @@ -614,9 +611,9 @@ namespace winstd // Preallocate array. for (param_count = 0; param_count < MAX_EVENT_DATA_DESCRIPTORS; param_count++) { const EVENT_DATA_DESCRIPTOR &p = va_arg(arg, const EVENT_DATA_DESCRIPTOR); - if (p.Ptr == winstd::event_data::blank.Ptr && - p.Size == winstd::event_data::blank.Size && - p.Reserved == winstd::event_data::blank.Reserved) break; + if (p.Ptr == winstd::blank_event_data.Ptr && + p.Size == winstd::blank_event_data.Size && + p.Reserved == winstd::blank_event_data.Reserved) break; } params.reserve(param_count); @@ -624,9 +621,9 @@ namespace winstd arg = arg_start; for (;;) { const EVENT_DATA_DESCRIPTOR &p = va_arg(arg, const EVENT_DATA_DESCRIPTOR); - if (p.Ptr == winstd::event_data::blank.Ptr && - p.Size == winstd::event_data::blank.Size && - p.Reserved == winstd::event_data::blank.Reserved) break; + if (p.Ptr == winstd::blank_event_data.Ptr && + p.Size == winstd::blank_event_data.Size && + p.Reserved == winstd::blank_event_data.Reserved) break; params.push_back(p); }