From 20fde6766e3272dce7e89c26d1f2437053f246ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Mon, 9 Dec 2024 23:15:05 +0200 Subject: [PATCH] Optimize path start state This adds a fast path for URLs like `ws://h`, `ws://h\` and `ws://h/` that parse to `ws://h/`. --- include/upa/url.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/upa/url.h b/include/upa/url.h index 2a4cd62..06868a2 100644 --- a/include/upa/url.h +++ b/include/upa/url.h @@ -2167,6 +2167,14 @@ inline validation_errc url_parser::url_parse(url_serializer& urls, const CharT* ++pointer; } } + if (pointer == last) { + // Optimization: + // "ws://h", "ws://h\" and "ws://h/" parses to "ws://h/" + // See: https://github.com/whatwg/url/pull/847 + urls.append_empty_path_segment(); + urls.commit_path(); + return validation_errc::ok; + } state = path_state; } else if (pointer != last) { if (!state_override) {