diff options
| author | Martin Hořeňovský | 2026-02-15 21:43:54 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-02-15 21:43:54 +0100 |
| commit | edfed6c04eb3b5734bb74b9048f67f9e0cc45a01 (patch) | |
| tree | 5dd5eff9c66e184a191861a5e3519bc5b17a52b4 /src/catch2/generators | |
| parent | 75bfcc3f305b0f4506d50c5b5f41891005442284 (diff) | |
| download | catch3-edfed6c04eb3b5734bb74b9048f67f9e0cc45a01.tar.gz | |
Efficient skipToNthElementImpl for Take and Map generators
Diffstat (limited to 'src/catch2/generators')
| -rw-r--r-- | src/catch2/generators/catch_generators_adapters.hpp | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/src/catch2/generators/catch_generators_adapters.hpp b/src/catch2/generators/catch_generators_adapters.hpp index c46cb927..7e21671a 100644 --- a/src/catch2/generators/catch_generators_adapters.hpp +++ b/src/catch2/generators/catch_generators_adapters.hpp @@ -30,13 +30,8 @@ namespace Generators { "Coud not jump to Nth element: not enough elements" ); } - for (; m_returned < n; ++m_returned) { - const auto success = m_generator.next(); - if ( !success ) { - Detail::throw_generator_exception( - "Coud not jump to Nth element: not enough elements" ); - } - } + m_generator.skipToNthElement( n ); + m_returned = n; } public: @@ -186,17 +181,8 @@ namespace Generators { mutable Optional<T> m_cache; void skipToNthElementImpl( std::size_t n ) override { - for ( size_t curr = GeneratorUntypedBase::currentElementIndex(); - curr < n; - ++curr ) { - const auto success = m_generator.next(); - if (!success) { - Detail::throw_generator_exception( - "Coud not jump to Nth element: not enough elements" ); - } - } - - m_cache = m_function( m_generator.get() ); + m_generator.skipToNthElement( n ); + m_cache.reset(); } public: |