Skip to content

Commit

Permalink
storage/curl: eliminate std::strings, parse string_view directly
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 4, 2024
1 parent b601f4d commit c04490b
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/storage/plugins/CurlStorage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "util/ASCII.hxx"
#include "util/NumberParser.hxx"
#include "util/SpanCast.hxx"
#include "util/StringCompare.hxx"
#include "util/StringSplit.hxx"
Expand Down Expand Up @@ -160,21 +161,18 @@ struct DavResponse {

[[gnu::pure]]
static unsigned
ParseStatus(const char *s) noexcept
ParseStatus(std::string_view s) noexcept
{
/* skip the "HTTP/1.1" prefix */
const char *space = std::strchr(s, ' ');
if (space == nullptr)
return 0;
const auto [http_1_1, rest] = Split(s, ' ');

return strtoul(space + 1, nullptr, 10);
}
/* skip the string suffix */
const auto [status_string, _] = Split(rest, ' ');

[[gnu::pure]]
static unsigned
ParseStatus(std::string_view s) noexcept
{
return ParseStatus(std::string{s}.c_str());
if (const auto status = ParseInteger<unsigned>(status_string))
return *status;

return 0;
}

[[gnu::pure]]
Expand All @@ -191,18 +189,14 @@ ParseTimeStamp(std::string_view s) noexcept
return ParseTimeStamp(std::string{s}.c_str());
}

[[gnu::pure]]
static uint64_t
ParseU64(const char *s) noexcept
{
return strtoull(s, nullptr, 10);
}

[[gnu::pure]]
static uint64_t
ParseU64(std::string_view s) noexcept
{
return ParseU64(std::string{s}.c_str());
if (const auto i = ParseInteger<uint_least64_t>(s))
return *i;

return 0;
}

[[gnu::pure]]
Expand Down

0 comments on commit c04490b

Please sign in to comment.