aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-strlen.c
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-02-11 17:14:22 -0500
committerPatrick Palka <ppalka@redhat.com>2020-02-28 09:33:03 -0500
commita15350157862db3631772b4ae69a9c9e3b0fab6e (patch)
tree703d6013dfaa6ab7236a014c8d100cf9bbfed274 /gcc/tree-ssa-strlen.c
parenta51a546c1704cd572c35c11e539568c04d99e7d1 (diff)
downloadgcc-a15350157862db3631772b4ae69a9c9e3b0fab6e.zip
gcc-a15350157862db3631772b4ae69a9c9e3b0fab6e.tar.gz
gcc-a15350157862db3631772b4ae69a9c9e3b0fab6e.tar.bz2
libstdc++: Memoize {drop,drop_while,filter,reverse}_view::begin
This patch adds memoization to these four views so that their begin() has the required amortized constant time complexity. The cache is enabled only for forward_ranges and above because we need the underlying iterator to be copyable and multi-pass in order for the cache to be usable. In the general case we represent the cached result of begin() as a bare iterator. This takes advantage of the fact that value-initialized forward iterators can be compared to as per N3644, so we can use a value-initialized iterator to denote the "empty" state of the cache. As a special case, when the underlying range models random_access_range and when it's profitable size-wise, then we cache the offset of the iterator from the beginning of the range instead of caching the iterator itself. Additionally, in drop_view and reverse_view we disable the cache when the underlying range models random_access_range, because in these cases recomputing begin() takes O(1) time anyway. libstdc++-v3/ChangeLog: * include/std/ranges (__detail::_CachedPosition): New struct. (views::filter_view::_S_needs_cached_begin): New member variable. (views::filter_view::_M_cached_begin): New member variable. (views::filter_view::begin): Use _M_cached_begin to cache its result. (views::drop_view::_S_needs_cached_begin): New static member variable. (views::drop_view::_M_cached_begin): New member variable. (views::drop_view::begin): Use _M_cached_begin to cache its result when _S_needs_cached_begin. (views::drop_while_view::_M_cached_begin): New member variable. (views::drop_while_view::begin): Use _M_cached_begin to cache its result. (views::reverse_view::_S_needs_cached_begin): New static member variable. (views::reverse_view::_M_cached_begin): New member variable. (views::reverse_view::begin): Use _M_cached_begin to cache its result when _S_needs_cached_begin. * testsuite/std/ranges/adaptors/drop.cc: Augment test to check that drop_view::begin caches its result. * testsuite/std/ranges/adaptors/drop_while.cc: Augment test to check that drop_while_view::begin caches its result. * testsuite/std/ranges/adaptors/filter.cc: Augment test to check that filter_view::begin caches its result. * testsuite/std/ranges/adaptors/reverse.cc: Augment test to check that reverse_view::begin caches its result.
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
0 files changed, 0 insertions, 0 deletions