1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

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.
This commit is contained in:
John Ericson 2025-08-25 15:31:40 -04:00
parent fac34ad20f
commit e4e8a615fa

View file

@ -68,8 +68,10 @@ try {
ParsedURL ParsedS3URL::toHttpsUrl() const ParsedURL ParsedS3URL::toHttpsUrl() const
{ {
std::string regionStr = region.value_or("us-east-1"); auto toView = [](const auto & x) { return std::string_view{x}; };
std::string schemeStr = scheme.value_or("https");
auto regionStr = region.transform(toView).value_or("us-east-1");
auto schemeStr = scheme.transform(toView).value_or("https");
// Handle endpoint configuration using std::visit // Handle endpoint configuration using std::visit
return std::visit( return std::visit(
@ -77,7 +79,7 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
[&](const std::monostate &) { [&](const std::monostate &) {
// No custom endpoint, use standard AWS S3 endpoint // No custom endpoint, use standard AWS S3 endpoint
return ParsedURL{ return ParsedURL{
.scheme = schemeStr, .scheme = std::string{schemeStr},
.authority = ParsedURL::Authority{.host = "s3." + regionStr + ".amazonaws.com"}, .authority = ParsedURL::Authority{.host = "s3." + regionStr + ".amazonaws.com"},
.path = (CanonPath::root / bucket / CanonPath(key)).abs(), .path = (CanonPath::root / bucket / CanonPath(key)).abs(),
}; };
@ -85,7 +87,7 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
[&](const ParsedURL::Authority & auth) { [&](const ParsedURL::Authority & auth) {
// Endpoint is just an authority (hostname/port) // Endpoint is just an authority (hostname/port)
return ParsedURL{ return ParsedURL{
.scheme = schemeStr, .scheme = std::string{schemeStr},
.authority = auth, .authority = auth,
.path = (CanonPath::root / bucket / CanonPath(key)).abs(), .path = (CanonPath::root / bucket / CanonPath(key)).abs(),
}; };