Skip to content

Commit

Permalink
Add noexcept clause to various string_view functions
Browse files Browse the repository at this point in the history
  • Loading branch information
davmac314 committed Nov 26, 2023
1 parent 9f81dca commit 41952f6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/includes/dinit-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@ class string_view
public:
string_view() = default;
string_view(const string_view &other) = default;
string_view(const char *s_p, size_t count_p) : s(s_p), count(count_p) { }
string_view(const char *s_p) : s(s_p), count(strlen(s_p)) { }
string_view(const char *s_p, size_t count_p) noexcept : s(s_p), count(count_p) { }
string_view(const char *s_p) noexcept : s(s_p), count(strlen(s_p)) { }

string_view(const std::string &str) : s(str.data()), count(str.length()) { }

string_view &operator=(const string_view &other) = default;

bool operator==(const string_view &other) const
bool operator==(const string_view &other) const noexcept
{
if (count != other.count) return false;
return memcmp(s, other.s, count) == 0;
}

bool operator==(const char *other) const
bool operator==(const char *other) const noexcept
{
if (strncmp(s, other, count) == 0) {
if (other[count] == '\0') {
Expand All @@ -181,10 +181,10 @@ class string_view
return false;
}

const char *data() const { return s; }
size_t size() const { return count; }
size_t length() const { return count; }
bool empty() const { return count == 0; }
const char *data() const noexcept { return s; }
size_t size() const noexcept { return count; }
size_t length() const noexcept { return count; }
bool empty() const noexcept { return count == 0; }
};

inline size_t hash(const string_view &str)
Expand Down

0 comments on commit 41952f6

Please sign in to comment.