[clang] [NFC][clang][AST] Add compile-time dispatch for random access iterators in append() (PR #162000)
Samarth Narang via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 5 21:56:48 PDT 2025
================
@@ -192,9 +204,11 @@ class ASTVector {
this->grow(C, this->size()+NumInputs);
// Copy the new elements over.
- // TODO: NEED To compile time dispatch on whether in_iter is a random access
- // iterator to use the fast uninitialized_copy.
----------------
snarang181 wrote:
@zwuis,thanks for your review.
std::distance and std::uninitialized_copy both rely on iterator tag dispatch, which determines the implementation at overload resolution time rather than through explicit compile-time branching. While std::distance will use an O(1) path for random access iterators, that dispatch happens inside the library and isn’t guaranteed to inline cleanly into templated call sites like append(). Moreover, std::uninitialized_copy always performs an element-by-element loop regardless of iterator category, offering no benefit when the range size (NumInputs) is already known. Using std::uninitialized_copy_n with a precomputed element count avoids the per-iteration sentinel checks and enables the compiler to generate tighter loops.
https://github.com/llvm/llvm-project/pull/162000
More information about the cfe-commits
mailing list