ctl string const/value tweaks (#1218)

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.

At function definition (as opposed to prototype), we add const to values
in parameters by default, unless we’re going to mutate them.

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:
Steven Dee (Jōshin) 2024-06-15 18:09:05 -07:00
parent ddfaf3fee0
commit e38a6e7996
No known key found for this signature in database
4 changed files with 51 additions and 48 deletions

View file

@ -26,7 +26,7 @@
namespace ctl {
size_t
string_view::find(char ch, size_t pos) const noexcept
string_view::find(const char ch, const size_t pos) const noexcept
{
char* q;
if (n && (q = (char*)memchr(p, ch, n)))
@ -35,7 +35,7 @@ string_view::find(char ch, size_t pos) const noexcept
}
size_t
string_view::find(const string_view s, size_t pos) const noexcept
string_view::find(const string_view s, const size_t pos) const noexcept
{
char* q;
if (pos > n)
@ -46,7 +46,7 @@ string_view::find(const string_view s, size_t pos) const noexcept
}
string_view
string_view::substr(size_t pos, size_t count) const noexcept
string_view::substr(const size_t pos, size_t count) const noexcept
{
size_t last;
if (pos > n)