mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-12 02:13:36 +00:00
Replace static constexpr with inline constexpr in header (#4613)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4613 Replace `static constexpr` with `inline constexpr` for the `hamdis_tab_ham_bytes` array in the header file to fix namespace-level static linkage issue. Using `static` at namespace level in a header file causes a separate copy of the aggregate to appear in every compilation unit that includes the header, which is inefficient and violates best practices. The `inline constexpr` specifier (C++17) provides external linkage while ensuring only one definition exists across all translation units. This change implements the TODO that was already documented in the code comments, as Faiss uses C++17 (confirmed in CMakeLists.txt). The table remains in the header file as required for SWIG compilation on Windows, but now uses the correct modern C++ approach. Reviewed By: limqiying Differential Revision: D84858704 fbshipit-source-id: 0ea502399e3bb3943474cd56b6112dabc7370ee7
This commit is contained in:
committed by
meta-codesync[bot]
parent
3af3e00103
commit
513eabc91d
@@ -30,8 +30,7 @@ inline int popcount64(uint64_t x) {
|
||||
// This table was moved from .cpp to .h file, because
|
||||
// otherwise it was causing compilation errors while trying to
|
||||
// compile swig modules on Windows.
|
||||
// todo for C++17: switch to 'inline constexpr'
|
||||
static constexpr uint8_t hamdis_tab_ham_bytes[256] = {
|
||||
inline constexpr uint8_t hamdis_tab_ham_bytes[256] = {
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
|
||||
Reference in New Issue
Block a user