Files
ladybird/Libraries/LibURL/Parser.cpp
Shannon Booth c8dc5ea27c LibURL: Optimize parsing of URLs in authority state
Previously the authority state was parsed character-by-character in a
loop, appending each character to a buffer. When an '@' character was
encountered, the entire buffer would be re-processed to extract and
percent-encode the username and password portions.

This created O(n^2) behavior for URLs with multiple '@' characters, as
each '@' would trigger reprocessing of all previously buffered content.

This commit changes the authority state parser to process the authority
section in chunks rather than character-by-character:

1. Find the next delimiter ('@', '/', '?', '#', or '\' for special URLs)
2. Process the entire chunk up to that delimiter at once
3. Directly extract username/password from the chunk without buffering

With an additional change of switching to:
iterator_at_byte_offset_without_validation (which does not have any
loops), this reduces the time complexity to O(n) and the included
test found by fuzzing to actually complete parsing :^)
2026-01-26 18:46:59 +01:00

73 KiB