mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 11:12:27 +00:00
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:
parent
ddfaf3fee0
commit
e38a6e7996
4 changed files with 51 additions and 48 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue