mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-03 08:20:28 +00:00
Move isbig() into header
Takes 1ns off most benchmarks where the destructor is frequently called.
This commit is contained in:
parent
9a5a13854d
commit
be005b63e3
2 changed files with 18 additions and 12 deletions
|
@ -23,20 +23,19 @@
|
|||
|
||||
namespace ctl {
|
||||
|
||||
string::~string() noexcept
|
||||
void
|
||||
string::destroy_big() noexcept
|
||||
{
|
||||
if (isbig()) {
|
||||
auto* b = big();
|
||||
if (b->n) {
|
||||
if (b->n >= b->c)
|
||||
__builtin_trap();
|
||||
if (b->p[b->n])
|
||||
__builtin_trap();
|
||||
}
|
||||
if (b->c && !b->p)
|
||||
auto* b = big();
|
||||
if (b->n) {
|
||||
if (b->n >= b->c)
|
||||
__builtin_trap();
|
||||
if (b->p[b->n])
|
||||
__builtin_trap();
|
||||
free(b->p);
|
||||
}
|
||||
if (b->c && !b->p)
|
||||
__builtin_trap();
|
||||
free(b->p);
|
||||
}
|
||||
|
||||
string::string(const char* s) noexcept : string()
|
||||
|
|
|
@ -48,7 +48,12 @@ class string
|
|||
using const_iterator = const char*;
|
||||
static constexpr size_t npos = -1;
|
||||
|
||||
~string() /* noexcept */;
|
||||
~string() /* noexcept */
|
||||
{
|
||||
if (isbig())
|
||||
destroy_big();
|
||||
}
|
||||
|
||||
string(string_view) noexcept;
|
||||
string(const char*) noexcept;
|
||||
string(const string&) noexcept;
|
||||
|
@ -277,6 +282,8 @@ class string
|
|||
}
|
||||
|
||||
private:
|
||||
void destroy_big() noexcept;
|
||||
|
||||
inline bool isbig() const noexcept
|
||||
{
|
||||
return *(blob + __::sso_max) & 0x80;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue