[all-commits] [llvm/llvm-project] 982744: [libc++] Optimize ranges::{for_each, for_each_n} f...

Peng Liu via All-commits all-commits at lists.llvm.org
Wed Jun 18 09:23:09 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9827440f1e723423baf4c235e844eb8ac48a8f97
      https://github.com/llvm/llvm-project/commit/9827440f1e723423baf4c235e844eb8ac48a8f97
  Author: Peng Liu <winner245 at hotmail.com>
  Date:   2025-06-18 (Wed, 18 Jun 2025)

  Changed paths:
    M libcxx/docs/ReleaseNotes/21.rst
    M libcxx/include/__algorithm/for_each.h
    M libcxx/include/__algorithm/for_each_n.h
    M libcxx/include/__algorithm/ranges_for_each.h
    M libcxx/include/__algorithm/ranges_for_each_n.h
    M libcxx/include/experimental/iterator
    M libcxx/include/mutex
    M libcxx/include/shared_mutex
    M libcxx/test/benchmarks/algorithms/nonmodifying/for_each.bench.cpp
    M libcxx/test/benchmarks/algorithms/nonmodifying/for_each_n.bench.cpp
    M libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
    M libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp

  Log Message:
  -----------
  [libc++] Optimize ranges::{for_each, for_each_n} for segmented iterators (#132896)

Previously, the segmented iterator optimization was limited to `std::{for_each, for_each_n}`. This patch
extends the optimization to `std::ranges::for_each` and `std::ranges::for_each_n`, ensuring consistent
optimizations across these algorithms. This patch first generalizes the `std` algorithms by introducing
a `Projection` parameter, which is set to `__identity` for the `std` algorithms. Then we let the `ranges`
algorithms to directly call their `std` counterparts with a general `__proj` argument. Benchmarks
demonstrate performance improvements of up to 21.4x for ``std::deque::iterator`` and 22.3x for
``join_view`` of ``vector<vector<char>>``.

Addresses a subtask of #102817.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list