[all-commits] [llvm/llvm-project] 298183: [ADT] Add `llvm::range_size` function for generic ...

Jakub Kuderski via All-commits all-commits at lists.llvm.org
Tue Mar 21 10:00:23 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2981832501f7bca6dc95ba54af68bdd1766629c4
      https://github.com/llvm/llvm-project/commit/2981832501f7bca6dc95ba54af68bdd1766629c4
  Author: Jakub Kuderski <kubakuderski at gmail.com>
  Date:   2023-03-21 (Tue, 21 Mar 2023)

  Changed paths:
    M llvm/include/llvm/ADT/STLExtras.h
    M llvm/unittests/ADT/IteratorTest.cpp
    M llvm/unittests/ADT/STLExtrasTest.cpp

  Log Message:
  -----------
  [ADT] Add `llvm::range_size` function for generic ranges

This function follows `std::ranges::size` from C++20. It is intended
mainly for generic code that does not know the exact range type.
I did not modify the existing `llvm::size` function because it has a strict
guarantee of O(1) running time, and we cannot guarantee that when we delegate
size check to user-defined size functions.

Use `range_size` to optimize size checks in `zip`* and `enumerate`
functions. Before that, we would have to perform linear scans for ranges
without random access iterators.

This is the last change I have planned in the series that overhauls
`zip`* and `enumerate`.

Reviewed By: dblaikie, zero9178

Differential Revision: https://reviews.llvm.org/D146231




More information about the All-commits mailing list