Move isbig() into header

Takes 1ns off most benchmarks where the destructor is frequently called.
This commit is contained in:
Steven Dee (Jōshin) 2024-06-18 16:12:58 -07:00
parent 9a5a13854d
commit be005b63e3
No known key found for this signature in database
2 changed files with 18 additions and 12 deletions

View file

@ -23,20 +23,19 @@
namespace ctl { namespace ctl {
string::~string() noexcept void
string::destroy_big() noexcept
{ {
if (isbig()) { auto* b = big();
auto* b = big(); if (b->n) {
if (b->n) { if (b->n >= b->c)
if (b->n >= b->c) __builtin_trap();
__builtin_trap(); if (b->p[b->n])
if (b->p[b->n])
__builtin_trap();
}
if (b->c && !b->p)
__builtin_trap(); __builtin_trap();
free(b->p);
} }
if (b->c && !b->p)
__builtin_trap();
free(b->p);
} }
string::string(const char* s) noexcept : string() string::string(const char* s) noexcept : string()

View file

@ -48,7 +48,12 @@ class string
using const_iterator = const char*; using const_iterator = const char*;
static constexpr size_t npos = -1; static constexpr size_t npos = -1;
~string() /* noexcept */; ~string() /* noexcept */
{
if (isbig())
destroy_big();
}
string(string_view) noexcept; string(string_view) noexcept;
string(const char*) noexcept; string(const char*) noexcept;
string(const string&) noexcept; string(const string&) noexcept;
@ -277,6 +282,8 @@ class string
} }
private: private:
void destroy_big() noexcept;
inline bool isbig() const noexcept inline bool isbig() const noexcept
{ {
return *(blob + __::sso_max) & 0x80; return *(blob + __::sso_max) & 0x80;