From f67fc0c19b9d30418a4c659d3cf3ddd679c6ab49 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 10 Sep 2025 16:46:37 -0700 Subject: [PATCH] [Support] Merge two implementations of addRangeElementsImpl (NFC) This patch uses "constexpr if" to merge two implementations of addRangeElementsImpl. While the line count does not change much, the "if" condition should be a lot more readable than in std::enable_if. --- llvm/include/llvm/Support/HashBuilder.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/llvm/include/llvm/Support/HashBuilder.h b/llvm/include/llvm/Support/HashBuilder.h index 097110874400d..17fbc3f96ed04 100644 --- a/llvm/include/llvm/Support/HashBuilder.h +++ b/llvm/include/llvm/Support/HashBuilder.h @@ -366,18 +366,16 @@ class HashBuilder : public HashBuilderBase { HashBuilder &addRangeElementsImpl(ForwardIteratorT First, ForwardIteratorT Last, std::forward_iterator_tag) { - for (auto It = First; It != Last; ++It) - add(*It); - return *this; - } - - template - std::enable_if_t::value && - Endianness == llvm::endianness::native, - HashBuilder &> - addRangeElementsImpl(T *First, T *Last, std::forward_iterator_tag) { - this->update(ArrayRef(reinterpret_cast(First), - (Last - First) * sizeof(T))); + using T = typename std::iterator_traits::value_type; + if constexpr (std::is_pointer_v && + hashbuilder_detail::IsHashableData::value && + Endianness == llvm::endianness::native) { + this->update(ArrayRef(reinterpret_cast(First), + (Last - First) * sizeof(T))); + } else { + for (auto It = First; It != Last; ++It) + add(*It); + } return *this; } };