GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

libstdc++: Optimize ranges::for_each for segmented iterators

Optimizes std::for_each for segmented iterators, improving performance.

This change optimizes the std::for_each algorithm when used with segmented iterators. Similar to a previous optimization for std::ranges::for_each, this update specifically targets the std::for_each implementation. The naive for-loop logic has been separated and optimized for segmented iterators. A performance benchmark for ranges::for_each has also been added to the test suite.

In Details

This commit optimizes libstdc++'s ranges::for_each implementation for segmented iterators. It refactors the __for_each function in ranges_algo.h to handle segmented iterators more efficiently by splitting out the naive for-loop logic. This aims to reduce overhead when iterating over segmented data structures.

Filed Under: libstdc++optimizationiterator