Skip to content

Commit b22a97d

Browse files
[Support] Merge two implementations of addRangeElementsImpl (NFC) (#158212)
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.
1 parent 889c289 commit b22a97d

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

llvm/include/llvm/Support/HashBuilder.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,16 @@ class HashBuilder : public HashBuilderBase<HasherT> {
366366
HashBuilder &addRangeElementsImpl(ForwardIteratorT First,
367367
ForwardIteratorT Last,
368368
std::forward_iterator_tag) {
369-
for (auto It = First; It != Last; ++It)
370-
add(*It);
371-
return *this;
372-
}
373-
374-
template <typename T>
375-
std::enable_if_t<hashbuilder_detail::IsHashableData<T>::value &&
376-
Endianness == llvm::endianness::native,
377-
HashBuilder &>
378-
addRangeElementsImpl(T *First, T *Last, std::forward_iterator_tag) {
379-
this->update(ArrayRef(reinterpret_cast<const uint8_t *>(First),
380-
(Last - First) * sizeof(T)));
369+
using T = typename std::iterator_traits<ForwardIteratorT>::value_type;
370+
if constexpr (std::is_pointer_v<ForwardIteratorT> &&
371+
hashbuilder_detail::IsHashableData<T>::value &&
372+
Endianness == llvm::endianness::native) {
373+
this->update(ArrayRef(reinterpret_cast<const uint8_t *>(First),
374+
(Last - First) * sizeof(T)));
375+
} else {
376+
for (auto It = First; It != Last; ++It)
377+
add(*It);
378+
}
381379
return *this;
382380
}
383381
};

0 commit comments

Comments
 (0)