From 2dd8273fe764db4250a002cc6427b024e6cb0fe5 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 3 Dec 2024 16:09:03 +0900 Subject: [PATCH] Remove platform macros from `tip_text_service.cc` This commit removes the dependency on platform macros such as _M_X64 and _M_IX86 from tip_text_service.cc. There must be no change in the final artifacts. This is a preparation to build Mozc for ARM64 (#1130). --- src/win32/tip/tip_text_service.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/win32/tip/tip_text_service.cc b/src/win32/tip/tip_text_service.cc index 71aafdb7f4..3846cfd5a6 100644 --- a/src/win32/tip/tip_text_service.cc +++ b/src/win32/tip/tip_text_service.cc @@ -36,8 +36,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -249,15 +251,11 @@ wil::com_ptr_nothrow GetCategoryMgr() { template struct ComPtrHash { size_t operator()(const wil::com_ptr_nothrow &value) const { - // Caveats: On x86 environment, both _M_X64 and _M_IX86 are defined. So we - // need to check _M_X64 first. -#if defined(_M_X64) - constexpr size_t kUnusedBits = 3; // assuming 8-byte aligned -#elif defined(_M_IX86) // defined(_M_X64) - constexpr size_t kUnusedBits = 2; // assuming 4-byte aligned -#else // defined(_M_IX86) -#error "unsupported platform" -#endif // defined(_M_IX86) + // The minimum size of COM objects is the pointer to vtable. + // For instance the last 3 bits are guaranteed to be zero on 64-bit + // processes. + constexpr size_t kUnusedBits = + std::max(std::bit_width(sizeof(void *)), 1) - 1; // Compress the data by shifting unused bits. return reinterpret_cast(value.get()) >> kUnusedBits; }