From e4e8a615fada3f9a098c3dac09ba392d8ef7353d Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 25 Aug 2025 15:31:40 -0400 Subject: [PATCH] `ParsedS3URL::toHttpsUrl` Slight optimize I didn't want to block that PR on further code review while I figured out these new (to us) C++23 goodies. --- src/libstore/s3.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libstore/s3.cc b/src/libstore/s3.cc index e58006f03..739de2532 100644 --- a/src/libstore/s3.cc +++ b/src/libstore/s3.cc @@ -68,8 +68,10 @@ try { ParsedURL ParsedS3URL::toHttpsUrl() const { - std::string regionStr = region.value_or("us-east-1"); - std::string schemeStr = scheme.value_or("https"); + auto toView = [](const auto & x) { return std::string_view{x}; }; + + auto regionStr = region.transform(toView).value_or("us-east-1"); + auto schemeStr = scheme.transform(toView).value_or("https"); // Handle endpoint configuration using std::visit return std::visit( @@ -77,7 +79,7 @@ ParsedURL ParsedS3URL::toHttpsUrl() const [&](const std::monostate &) { // No custom endpoint, use standard AWS S3 endpoint return ParsedURL{ - .scheme = schemeStr, + .scheme = std::string{schemeStr}, .authority = ParsedURL::Authority{.host = "s3." + regionStr + ".amazonaws.com"}, .path = (CanonPath::root / bucket / CanonPath(key)).abs(), }; @@ -85,7 +87,7 @@ ParsedURL ParsedS3URL::toHttpsUrl() const [&](const ParsedURL::Authority & auth) { // Endpoint is just an authority (hostname/port) return ParsedURL{ - .scheme = schemeStr, + .scheme = std::string{schemeStr}, .authority = auth, .path = (CanonPath::root / bucket / CanonPath(key)).abs(), };