Skip to content

Commit

Permalink
Remove platform macros from tip_text_service.cc
Browse files Browse the repository at this point in the history
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 (google#1130).
  • Loading branch information
yukawa committed Dec 3, 2024
1 parent 006ed69 commit 2dd8273
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/win32/tip/tip_text_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
#include <wil/com.h>
#include <windows.h>

#include <bit>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <utility>
Expand Down Expand Up @@ -249,15 +251,11 @@ wil::com_ptr_nothrow<ITfCategoryMgr> GetCategoryMgr() {
template <typename T>
struct ComPtrHash {
size_t operator()(const wil::com_ptr_nothrow<T> &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<size_t>(value.get()) >> kUnusedBits;
}
Expand Down

0 comments on commit 2dd8273

Please sign in to comment.