From 306e0cace6cc3ea9779a1a07fb8f0ed398c2292e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Sun, 14 Jul 2024 08:47:24 +0300 Subject: [PATCH] Optimize url::can_parse: do not reserve memory for URL string --- include/upa/url.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/upa/url.h b/include/upa/url.h index def36cd..a36f076 100644 --- a/include/upa/url.h +++ b/include/upa/url.h @@ -1599,9 +1599,11 @@ inline validation_errc url_parser::url_parse(url_serializer& urls, const CharT* detail::do_remove_whitespace(first, last, buff_no_ws); //TODO-WARN: validation error if removed - // reserve size (TODO: But what if `base` is used?) - const auto length = std::distance(first, last); - urls.reserve(length + 32); + if (urls.need_save()) { + // reserve size (TODO: But what if `base` is used?) + const auto length = std::distance(first, last); + urls.reserve(length + 32); + } #ifdef UPA_URL_USE_ENCODING const char* encoding = "UTF-8";