[llvm] 7451bf0 - [SLP] use std::distance/find to reduce code; NFC

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 09:33:47 PDT 2020


On Thu, Sep 24, 2020 at 1:34 AM Florian Hahn <florian_hahn at apple.com> wrote:
>
>
>
> > On Sep 23, 2020, at 22:39, David Blaikie via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> >
> > Looks like this is a SmallVector, so it has random access iterators if
> > I'm reading the right code - could you use subtraction instead of
> > std::distance? (std::distance tends to be more relevant in generic
> > code where an iterator might not support random access, so it can fall
> > back to iteration to compute the difference)
>
>
> Or perhaps use llvm::size from STLExtras.h? https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/ADT/STLExtras.h#L1473
>
> This should only be available for iterators that guarantee the distance can be computed in O(1), although it then still delegates to std::distance.

That's more intended for use with an iterator range data type - which
isn't the case here (it'd end up being `size(make_range(begin, find))`
rather than `find - begin`)


More information about the llvm-commits mailing list