ladybird/Tests/AK
Timothy Flynn 911ecf1450 AK: Avoid copying the iterable container in AK::enumerate
There are actually a couple of issues here:

1. We are not properly perfect-forwarding the iterable to the Enumerator
   member. We are using the class template as the constructor type, but
   we would actually have to do something like this to achieve perfect
   forwarding:

   template <typname Iter = Iterable>
   Enumerator(Iter&&)

2. The begin / end methods on Enumerator (although they return by const-
   ref) are making copies during for-each loops. The compiler basically
   generates this when we call enumerate:

   for (auto it = Enumerator::begin(); it != Enumerator::end(); ++it)

   The creation of `it` above actually creates a copy of the returned
   Enumerator instance.

To avoid all of this, let's create an intermediate structure to act as
the enumerated iterator. This structure does not hold the iterable and
thus is fine to copy. We can then let the compiler handle forwarding
the iterable to the Enumerator.

Cherry-picked from:
0edcd19615
2025-11-18 13:31:52 +01:00
..
CMakeLists.txt AK+LibUnicode: Implement Unicode-aware UTF-16 case transformations 2025-07-25 18:16:22 +02:00
TestAKBindings.swift AK: Update Swift test for Utf16String changes 2025-07-26 23:33:58 +02:00
TestAllOf.cpp LibTest: Add more numeric generators 2024-01-12 16:42:51 -07:00
TestAnyOf.cpp LibTest: Add more numeric generators 2024-01-12 16:42:51 -07:00
TestArray.cpp AK: Conform SimpleIterator to the random access iterator requirements 2024-08-17 17:44:37 -06:00
TestAtomic.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestBadge.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestBase64.cpp AK: Add a Base64 decoder to decode into an existing buffer 2024-09-03 17:43:03 +02:00
TestBinaryHeap.cpp LibTest: Add more numeric generators 2024-01-12 16:42:51 -07:00
TestBinarySearch.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestBitCast.cpp Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
TestBitmap.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestBitStream.cpp LibTest: Add more numeric generators 2024-01-12 16:42:51 -07:00
TestBuiltinWrappers.cpp LibTest: Add more numeric generators 2024-01-12 16:42:51 -07:00
TestByteBuffer.cpp AK: Add an option to zero-fill ByteBuffer data upon growth 2023-12-27 19:30:39 +01:00
TestByteString.cpp AK: Remove unused UTF-8 / other factory methods from ByteString 2025-04-07 17:44:38 +02:00
TestCharacterTypes.cpp LibTest: Support death tests without child process cloning 2025-05-16 13:23:32 -06:00
TestChecked.cpp AK: Remove unused Checked<T> code 2025-10-22 00:26:23 +02:00
TestCircularBuffer.cpp Everywhere: Remove needless trailing semi-colons after functions 2023-07-08 10:32:56 +01:00
TestCircularQueue.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestDelayLoadWindows.cpp AK: Implement demangle() for MSVC ABI 2025-06-17 18:39:18 -06:00
TestDemangle.cpp AK: Implement demangle() for MSVC ABI 2025-06-17 18:39:18 -06:00
TestDisjointChunks.cpp Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
TestDistinctNumeric.cpp AK: Fix typo in -= operator of DistinctNumeric 2023-01-06 12:01:46 +01:00
TestDoublyLinkedList.cpp AK: Add some higher-level operations to DoublyLinkedList<T> 2025-08-08 12:54:06 +02:00
TestEndian.cpp AK: Add tests for LittleEndian<enum class> 2022-12-28 22:27:19 -05:00
TestEnumBits.cpp Everywhere: Fix even more typos 2025-08-27 08:48:01 +02:00
TestEnumerate.cpp AK: Avoid copying the iterable container in AK::enumerate 2025-11-18 13:31:52 +01:00
TestFind.cpp AK: Add an AK::find helper to return a reference to the found value 2025-04-06 13:45:10 +02:00
TestFixedArray.cpp AK+Tests: Remove NoAllocationGuard 2025-11-07 11:27:51 +01:00
TestFixedPoint.cpp AK: Stop exporting AK::FixedPoint into the global namespace 2024-07-18 09:43:38 +01:00
TestFlyString.cpp AK: Make "foo"_fly_string infallible 2023-08-07 16:03:27 +02:00
TestFormat.cpp AK+Tests: Add a formatter for Duration 2025-11-12 14:41:46 -06:00
TestFunction.mm AK: Support storing blocks in AK::Function 2025-03-18 17:15:08 -06:00
TestGenericLexer.cpp AK: Templatize GenericLexer for UTF-16 strings 2025-08-13 09:56:13 -04:00
TestGenericShorthands.cpp AK: Add first_is_equal_to_all_of() 2025-03-18 21:55:06 +01:00
TestHashFunctions.cpp AK+Meta+LibCore+Tests: Remove unused SipHash implementation 2025-04-06 01:47:50 +02:00
TestHashMap.cpp AK+Tests: Remove NoAllocationGuard 2025-11-07 11:27:51 +01:00
TestHashTable.cpp Tests: Add a test for HashTable<NonTrivial>::clear_with_capacity() 2025-09-22 17:28:00 -05:00
TestHex.cpp Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
TestIndexSequence.cpp AK: Make IndexSequence use size_t 2024-02-11 18:53:00 +01:00
TestInsertionSort.cpp Everywhere: Fix even more typos 2025-08-27 08:48:01 +02:00
TestIntegerMath.cpp AK: Add lowest common multiple and greatest common divisor functions 2025-04-23 09:13:45 +01:00
TestIntrusiveList.cpp AK: Fix crash during teardown of self-owning objects 2023-04-21 18:15:00 +02:00
TestIntrusiveRedBlackTree.cpp Everywhere: Remove NonnullOwnPtr.h includes 2023-03-06 23:46:35 +01:00
TestIPv4Address.cpp Everywhere: Fix even more typos 2025-08-27 08:48:01 +02:00
TestIPv6Address.cpp Everywhere: Fix even more typos 2025-08-27 08:48:01 +02:00
TestJSON.cpp Tests: Add a test for moving an object out of a JSON value 2025-02-24 12:05:29 -05:00
TestLEB128.cpp AK: Remove the fallible constructor from FixedMemoryStream 2023-02-08 17:44:32 +00:00
TestLexicalPath.cpp AK: Make LexicalPath::relative_path() fallible 2024-11-09 12:42:27 -07:00
TestMemory.cpp Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
TestMemoryStream.cpp AK: Add methods to BufferedStream to resize the user supplied buffer 2024-04-21 11:46:55 +02:00
TestNeverDestroyed.cpp Tests: Stop invoking UB in AK::NeverDestroyed's tests 2024-06-05 17:19:14 -06:00
TestNonnullOwnPtr.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestNonnullRefPtr.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestNumberFormat.cpp AK: Add human_readable_short_time() 2025-11-11 11:47:59 +01:00
TestOptional.cpp AK: Allow the Optional<T> move assignment operator to be trivial 2025-04-22 21:19:31 -06:00
TestOptionParser.cpp AK: Update OptionParser::m_arg_index by substracting skipped args 2024-02-06 00:08:30 +01:00
TestOwnPtr.cpp AK: Fix crash during teardown of self-owning objects 2023-04-21 18:15:00 +02:00
TestQueue.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestQuickSort.cpp Tests: Use AK_MAKE_DEFAULT_MOVABLE to avoid mistakes in default impls 2023-06-18 08:47:51 +01:00
TestRedBlackTree.cpp AK: Clear minimum when removing last node of RedBlackTree 2022-02-10 14:09:39 +00:00
TestRefPtr.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
TestSegmentedVector.cpp AK+LibWeb: Use segmented vector to store commands in RecordingPainter 2023-12-30 23:02:46 +01:00
TestSIMD.cpp Meta: Update my email address everywhere 2024-11-01 12:14:53 +01:00
TestSinglyLinkedList.cpp AK: Combine SinglyLinkedList and SinglyLinkedListWithCount 2023-01-02 20:13:24 +00:00
TestSourceGenerator.cpp AK: Make SourceGenerator::fork() infallible 2023-08-22 13:08:24 +02:00
TestSourceLocation.cpp Everywhere: Explicitly specify the size in StringView constructors 2022-07-12 23:11:35 +02:00
TestSpan.cpp AK: Add Span::ends_with() 2025-07-24 07:18:25 -04:00
TestStack.cpp Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
TestStdLibExtras.cpp AK: Make ceil_div() handle one argument being negative correctly 2024-04-27 07:09:08 +02:00
TestString.cpp AK: Replace surrogates in String::from_utf8_with_replacement_character 2025-07-06 04:30:17 +12:00
TestStringConversions.cpp Meta+Tests: Update fast-float to version 8.1.0 2025-09-25 21:14:29 -04:00
TestStringFloatingPointConversions.cpp AK: Define FloatingPointExponentialForm comparator in the AK namespace 2024-08-13 14:11:05 +02:00
TestStringUtils.cpp AK+Everywhere: Replace custom number parsers with fast_float 2025-07-03 09:51:56 -04:00
TestStringView.cpp AK: Ensure empty StringViews all compare as equal 2024-11-15 23:18:29 +01:00
TestTime.cpp AK+Tests: Add time units conversion functions to Duration 2025-11-17 16:51:18 +01:00
TestTrie.cpp Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
TestTuple.cpp Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
TestTypedTransfer.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
TestTypeTraits.cpp Everywhere: Remove needless trailing semi-colons after functions 2023-07-08 10:32:56 +01:00
TestUFixedBigInt.cpp AK: Make BigIntBase more agnostic to non native word sizes 2024-03-25 14:26:29 -06:00
TestUtf8View.cpp AK: Allow indexing at length in Utf8View::byte_offset_of() 2025-07-22 09:10:32 -04:00
TestUtf16FlyString.cpp AK: Specialize Optional for Utf16String and Utf16FlyString 2025-08-19 06:24:09 -04:00
TestUtf16String.cpp AK: Specialize Optional for Utf16String and Utf16FlyString 2025-08-19 06:24:09 -04:00
TestUtf16View.cpp AK+LibJS+LibWeb: Recognize that our UTF-16 string is actually WTF-16 2025-08-13 09:56:13 -04:00
TestVariant.cpp AK+Everywhere: Rename verify_cast to as 2025-01-21 11:34:06 -05:00
TestVector.cpp AK: Add Vector::remove_all(container)/remove_all(it, end) 2025-10-01 23:47:29 +02:00
TestWeakPtr.cpp Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00