From: Sam McCall Date: Wed, 5 Oct 2022 21:00:35 +0000 (+0200) Subject: [clangd] Avoid lexicographic compare when sorting SymbolIDs. NFC X-Git-Tag: upstream/17.0.6~31466 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=60b4b39f5a78661e2b9d222cf6ba7d9d5d7511ed;p=platform%2Fupstream%2Fllvm.git [clangd] Avoid lexicographic compare when sorting SymbolIDs. NFC These are 8 bytes and we don't care about the actual ordering, so use integer compare. The array generated code has some extra byte swaps (clang), calls memcmp (gcc) or inlines a big chain of comparisons (MSVC): https://godbolt.org/z/e79r6jM6K --- diff --git a/clang-tools-extra/clangd/index/SymbolID.h b/clang-tools-extra/clangd/index/SymbolID.h index d151208..e8aa462 100644 --- a/clang-tools-extra/clangd/index/SymbolID.h +++ b/clang-tools-extra/clangd/index/SymbolID.h @@ -39,7 +39,9 @@ public: } bool operator!=(const SymbolID &Sym) const { return !(*this == Sym); } bool operator<(const SymbolID &Sym) const { - return HashValue < Sym.HashValue; + // Avoid lexicographic compare which requires swapping bytes or even memcmp! + return llvm::bit_cast(HashValue) < + llvm::bit_cast(Sym.HashValue); } // The stored hash is truncated to RawSize bytes. @@ -56,6 +58,8 @@ public: explicit operator bool() const { return !isNull(); } private: + using IntTy = uint64_t; + static_assert(sizeof(IntTy) == RawSize); std::array HashValue{}; };