[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
This commit is contained in:
Sam McCall 2022-10-05 23:00:35 +02:00
parent 6bbe7d376e
commit 60b4b39f5a
1 changed files with 5 additions and 1 deletions

View File

@ -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<IntTy>(HashValue) <
llvm::bit_cast<IntTy>(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<uint8_t, RawSize> HashValue{};
};