ctl string const/value tweaks

The mangled name of a C++ function will typically not vary by const-ness
of a by-value parameter; in other words, there is no meaning to a const-
qualified by-value parameter in a function prototype. However, the const
keyword _does_ matter at function _definition_ time, like it does with a
variable declared in the body. So for prototypes, we strip out const for
by-value parameters; but for definitions, we leave them alone.

This commit also changes a couple of const string_view& to be simply by-
value string_view. A string_view is only two words; it rarely ever makes
sense to pass one by reference if it's not going to be mutated.
This commit is contained in:
Jōshin 2024-06-15 14:12:54 -07:00
parent 3a599bfbe1
commit c09c5121d8
No known key found for this signature in database
3 changed files with 19 additions and 20 deletions

View file

@ -289,7 +289,7 @@ string::substr(size_t pos, size_t count) const noexcept
}
string&
string::replace(size_t pos, size_t count, const string_view& s) noexcept
string::replace(size_t pos, size_t count, const string_view s) noexcept
{
size_t last;
if (ckd_add(&last, pos, count))

View file

@ -8,8 +8,7 @@ namespace ctl {
class string;
string
strcat(const string_view, const string_view) noexcept __wur;
string strcat(string_view, string_view) noexcept __wur;
namespace __ {
@ -50,7 +49,7 @@ class string
static constexpr size_t npos = -1;
~string() /* noexcept */;
string(const string_view) noexcept;
string(string_view) noexcept;
string(const char*) noexcept;
string(const string&) noexcept;
string(const char*, size_t) noexcept;
@ -67,17 +66,17 @@ class string
void append(char, size_t) noexcept;
void append(unsigned long) noexcept;
void append(const void*, size_t) noexcept;
string& insert(size_t, const string_view) noexcept;
string& insert(size_t, string_view) noexcept;
string& erase(size_t = 0, size_t = npos) noexcept;
string substr(size_t = 0, size_t = npos) const noexcept;
string& replace(size_t, size_t, const string_view&) noexcept;
bool operator==(const string_view) const noexcept;
bool operator!=(const string_view) const noexcept;
bool contains(const string_view) const noexcept;
bool ends_with(const string_view) const noexcept;
bool starts_with(const string_view) const noexcept;
string& replace(size_t, size_t, string_view) noexcept;
bool operator==(string_view) const noexcept;
bool operator!=(string_view) const noexcept;
bool contains(string_view) const noexcept;
bool ends_with(string_view) const noexcept;
bool starts_with(string_view) const noexcept;
size_t find(char, size_t = 0) const noexcept;
size_t find(const string_view, size_t = 0) const noexcept;
size_t find(string_view, size_t = 0) const noexcept;
string() noexcept
{
@ -330,7 +329,7 @@ class string
return reinterpret_cast<const __::big_string*>(blob);
}
friend string strcat(const string_view, const string_view);
friend string strcat(string_view, string_view);
alignas(union {
__::big_string a;

View file

@ -36,16 +36,16 @@ struct string_view
{
}
bool operator==(const string_view) const noexcept;
bool operator!=(const string_view) const noexcept;
bool contains(const string_view) const noexcept;
bool ends_with(const string_view) const noexcept;
bool starts_with(const string_view) const noexcept;
bool operator==(string_view) const noexcept;
bool operator!=(string_view) const noexcept;
bool contains(string_view) const noexcept;
bool ends_with(string_view) const noexcept;
bool starts_with(string_view) const noexcept;
string_view substr(size_t = 0, size_t = npos) const noexcept;
size_t find(char, size_t = 0) const noexcept;
size_t find(const string_view, size_t = 0) const noexcept;
size_t find(string_view, size_t = 0) const noexcept;
constexpr string_view& operator=(const string_view& s) noexcept
constexpr string_view& operator=(const string_view s) noexcept
{
p = s.p;
n = s.n;